Forum Discussion
If then in DAX Calculation
Hello All,
I am new to Power Bi.
I have small dax calculation. etc
I need if then else like below.
I created a table in power bi with these values APAC,EMEA and put in slicer
Now my requirement is
if Slicervalue ='APAC' then it has to check another conditions
Type= 'Phone' then the calculation like sum(Phonesales),
Type= 'Tablet' then the calculation like sum(Tabletsales)
else if Slicervalue ='EMEA'
condition Type= 'Phone' then the calculation like sum(Phonesales),
Type= 'Tablet' then the calculation like sum(Tabletsales) ....
not sure how to write this in dax.
Could any one please help
Hi Anonymous ,
I create the following sample data.
Then use the measure:
Measure = SWITCH ( SELECTEDVALUE ( Slicer[Name] ), "Phone", SUM ( DB_Region[Phonesales] ), "Tablet", SUM ( DB_Region[Tabletsales] ) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- vojtechsima
Super User
Hi, Anonymous
Try it like this:SWITCH(TRUE(), MAX('Table'[Slicer]) = "APAC", SWITCH(TRUE(), 'Table'[Type] = "Phone", SUM('Table'[Phonesales]), 'Table'[Type] = "Tablet", SUM('Table'[Tabletsales]) ), MAX('Table'[Slicer]) = "EMEA", SWITCH(TRUE(), 'Table'[Type] = "Phone", SUM('Table'[Phonesales]), 'Table'[Type] = "Tablet", SUM('Table'[Tabletsales]) ) )- AnonymousNot applicable
Hi vojtechsima,
Actually I explained my problem reversly.
Here Phone and Tablet are slicer values from a table I created in power bi
APAC and EMEA are region field values coming from Region table from db
Could you suggest how to change the above formula
- vojtechsima
Super User
Hi, Anonymous
Should be the same, only I forgot to add MAX:Measure2 = SWITCH(TRUE(), MAX('Table'[Slicer]) = "APAC", SWITCH(TRUE(), MAX('Table'[Type]) = "Phone", SUM('Table'[Phonesales]), MAX('Table'[Type]) = "Tablet", SUM('Table'[Tabletsales]) ), MAX('Table'[Slicer]) = "EMEA", SWITCH(TRUE(), MAX('Table'[Type]) = "Phone", SUM('Table'[Phonesales]), MAX('Table'[Type]) = "Tablet", SUM('Table'[Tabletsales]) ) )
- v-kkf-msft
Community Support
Hi Anonymous ,
I create the following sample data.
Then use the measure:
Measure = SWITCH ( SELECTEDVALUE ( Slicer[Name] ), "Phone", SUM ( DB_Region[Phonesales] ), "Tablet", SUM ( DB_Region[Tabletsales] ) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.