Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Odilon
Frequent Visitor

SWITCH or CASE in Query for data

I would like the query for the data in my visualization to filter for different values in a field depending on the case specified in a parameter. What is the correct syntax?

 

Something like:

 

let
    Source = Sql.Databases("RTPWDBDVIAN06"),
    weatherDB = Source{[Name="weatherDB"]}[Data],
    dbo_vw_WeatherData = weatherDB{[Schema="dbo",Item="vw_WeatherData"]}[Data],

 

CASE REGION

    REGION = "PA"
    #"Filtered Rows" = Table.SelectRows(dbo_vw_WeatherData, each ([WeatherStationCd] = "AOH" or [WeatherStationCd] = "ATL" ) and ([WeatherValueTypeCd] = "Temperature")),

    REGION = "NY

    #"Filtered Rows" = Table.SelectRows(dbo_vw_WeatherData, each ([WeatherStationCd] = "ALB" or [WeatherStationCd] = "BGM" ) and ([WeatherValueTypeCd] = "Temperature")),

 

in
    #"Filtered Rows"

 

 

The value for the Parameter REGION would be specified somewhere before the query runs

4 REPLIES 4
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Odilon,

 

Usually, we will do this with DAX rather than Power Query. In other words, we retrieve data from database and model it locally. The DAX formula could be like below.

Measure =
SWITCH (
    MIN ( 'table'[REGION] ),
    "PA", CALCULATE (
        SUM ( Sales[Quantity] ),
        'dbo_vw_WeatherData'[WeatherStationCd] IN { "AOH", "ATL" }
    ),
    "NY", CALCULATE (
        SUM ( Sales[Quantity] ),
        'dbo_vw_WeatherData'[WeatherStationCd] IN { "ALB", "BGM" }
    )
)

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Great! Thank you.

 

How do I specify REGION as a parameter the user "checks" to specify the Weather stations to which the visualizations are applied across the pages of the report?

Hi @Odilon,

 

You can either sync the slicers or use a Report Level filter. Please refer to the snapshot below.

SWITCH_or_CASE_in_Query_for_data

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you.

Once concern I have with defining a DAX measure restricted to a subset of data rather than restricting the data with the inititial Query is it seems in the first case I am "bringing" in all the data even though different users will only be using different subsets of the data.

Currently I have 2 reports, one for Region 1 and one for Region 2, associated with initital queries filtering to Region 1 or Region 2 Weather-Stations only.

The plus is users in each region only load data fro the report they need.

The disadvantage is I have to edit both reports every time I make a change.

Thoughts?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors