ID 13 - Filter using where condition like

Max: 45
Try code in DAX.do

Syntax

COUNT FILTER MID SELECTCOLUMNS

Related

34 - Split and Group By 35 - Find Customers with No Phone Number

SQL

SELECT customerName, country 
FROM customers 
WHERE country LIKE '_S%';

DAX

EVALUATE
SELECTCOLUMNS(
    FILTER(
        Customer,
        MID(Customer[CountryRegion], 2, 1) = "S"
    ),
    "CustomerName", Customer[Name],
    "Country", Customer[CountryRegion]
)

Pandas

import pandas as pd

df = pd.read_csv('customers.csv')

# Filter the DataFrame to include rows where the country has 'S' as the second character
result = df[df['country'].str.match(r'^.S')][['customerName', 'country']]

# Convert to a list of lists
result_list = result.values.tolist()

print(result_list)

Output

Mary Jones USA
Bob Brown USA
Alice White USA

Explanation

FILTER(Customers, MID(Customers[country], 2, 1) = "S"): Filters the Customers table to include rows where the second character of the country is 'S'. SELECTCOLUMNS: Selects the customerName and country columns and returns them as "CustomerName" and "Country" in the output.

Leave a Comment