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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
StuMortimer
New Member

Using a Case Statement Inside Summarise Columns

Hi Everyone,

 

I'm new to DAX but have been writing SQL for years. I'm struggling to find a way to include a switch statement inside of a summarise columns statement. I basically want to calculate a category on the fly like this...

 

EVALUATE

SUMMARIZECOLUMNS(
     PRODUCT[PROCUCT CODE],
     PRODUCT[PRODUCT NAME],

    "Product Category", SWITCH(PRODUCT[PROCUCT CODE], "00001", "Category 1", "00002", "Category 2", "Otherwise Unknown")

)

 

I can put a calculated column in the tabular data model i'm using but that seems like overkill because I just need it for this one report i'm working on. In SQL, i'd have just used a case statement and that would have been the end of it 🙂

 

Does anyone have any advice?

 

Many Thanks, Stu

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Include MAX, MIN or SELECTEDVALUE to your SWITCH and you should be good to go. Example:

Table 6 = SUMMARIZECOLUMNS(ItemExample[Item],ItemExample[Column],"Switch",SWITCH(MAX(ItemExample[Item]),"Item1","1","Item4","4","other"))

ValtteriN_0-1643721782414.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
ValtteriN
Super User
Super User

Hi,

Include MAX, MIN or SELECTEDVALUE to your SWITCH and you should be good to go. Example:

Table 6 = SUMMARIZECOLUMNS(ItemExample[Item],ItemExample[Column],"Switch",SWITCH(MAX(ItemExample[Item]),"Item1","1","Item4","4","other"))

ValtteriN_0-1643721782414.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.