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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Maha_0221
Frequent Visitor

Can you provide alternate dax without using SWITCH statement?

Suppose you have a table called Sales with columns for Region, Product, and Revenue.
You need to create a measure that categorizes the Revenue based on the Region using the following criteria:

If the Region is "North America" or "Europe", categorize the Revenue as "Developed Markets".
If the Region is "Asia" or "South America", categorize the Revenue as "Emerging Markets".
If the Region is anything else, categorize the Revenue as "Other Markets".
hope you can provide alternate result?

@Ashish_Mathur

1 ACCEPTED SOLUTION
v-nuoc-msft
Community Support
Community Support

Hi @Maha_0221 

 

@Ashish_Mathur  @AntrikshSharma Thank you very much for your prompt reply. Allow me to offer a different approach here.

 

@Maha_0221 For your question, here is the method I provided:

 

Here's some dummy data

 

Sales

vnuocmsft_0-1715063095626.png

 

You can create a measure. By calling a variable and making an if judgment.

 

Measure = 
VAR _REGION = SELECTEDVALUE('Sales'[region])
RETURN
IF(
    _REGION in {"North America", "Europe"}, 
    "Developed Narkets",
    IF(
        _REGION in {"Asia", "South America"},
        "Emerging Markets",
        "Other Markets"))

 

Using variables can better help you minimize the impact on performance.

 

Here is the result.

 

vnuocmsft_1-1715063321400.png

 

Regards,

Nono Chen

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

 

 

View solution in original post

6 REPLIES 6
v-nuoc-msft
Community Support
Community Support

Hi @Maha_0221 

 

@Ashish_Mathur  @AntrikshSharma Thank you very much for your prompt reply. Allow me to offer a different approach here.

 

@Maha_0221 For your question, here is the method I provided:

 

Here's some dummy data

 

Sales

vnuocmsft_0-1715063095626.png

 

You can create a measure. By calling a variable and making an if judgment.

 

Measure = 
VAR _REGION = SELECTEDVALUE('Sales'[region])
RETURN
IF(
    _REGION in {"North America", "Europe"}, 
    "Developed Narkets",
    IF(
        _REGION in {"Asia", "South America"},
        "Emerging Markets",
        "Other Markets"))

 

Using variables can better help you minimize the impact on performance.

 

Here is the result.

 

vnuocmsft_1-1715063321400.png

 

Regards,

Nono Chen

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

 

 

Ashish_Mathur
Super User
Super User

Hi,

If you insist on a measure, then try this one

Measure = if(hasonevalue(Data[Region]),if(min(Data[Region])="North America"||min(Data[Region])="Europe","Developed Markets",if(min(Data[Region])="Asia"||min(Data[Region])="South America","Emerging Markets","Other")),blank())

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AntrikshSharma
Community Champion
Community Champion

You can create another table that has region and category and either merge them or use a relationship, but what is the issue in creating a calculated column with SWITCH?

report performance issue

Create a calculated column not a measure

this was asked in interview so he want best answer for this question

Categorize_Revenue= switch(allselected(sales(region),{"North America","Europe"},"Developed Markets", {"Asia" or "South america"},"Emerging markets",other markets))

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.