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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lalTel20
Helper I
Helper I

How to perform calculations for category unig DAX

 

I wish to calculate the result based on my category. If the category is A then it is qty * parameter
if the category is B then qty * parameter * 3, and when category is C, then it should be qty. 
I am able to do that for each of the categories independently. But not in a one common measure. 
Can you please suggest how to do it? 

lalTel20_1-1606457651676.png

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@veenashenolikar , If these are parameters and they are dynamic, means coming from slicer or what if; you can not have a column.

 

if they are static, you can try column like

 

Switch( True() ,
(Table[category]) = "A" , 2 * Sum(Table[qty]),
(Table[category]) = "C" , 3 * Sum(Table[qty]),
(Table[qty])
)

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@veenashenolikar , If these are parameters and they are dynamic, means coming from slicer or what if; you can not have a column.

 

if they are static, you can try column like

 

Switch( True() ,
(Table[category]) = "A" , 2 * Sum(Table[qty]),
(Table[category]) = "C" , 3 * Sum(Table[qty]),
(Table[qty])
)

@lalTel20

Yes, it does that for measures. You will have to create a calculated column for that rather than a measure.

Get back to me if you need any more help.

amitchandak
Super User
Super User

@lalTel20 , Try a measure like

 

Sumx(Values(Table[category]) ,
Switch( True() ,
max(Table[category]) = "A" , selectedvalue(parameter1[parameter1]) * Sum(Table[qty]),
max(Table[category]) = "C" , selectedvalue(parameter3[parameter3]) * Sum(Table[qty]),
Sum(Table[qty])
)

@lalTel20 ,

 

You need to write a measure with Switch or IF-Else . Before that can you tell me if you have only 3 categories or are there more?

 

There are 5 categories. But the switch  / if function doesnt allow me to select a category to use in the function. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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