Reply
avatar user
Anonymous
Not applicable
Partially syndicated - Outbound

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

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

Syndicated - Outbound

Hi @Anonymous ,

 

I create the following sample data.

 

vkkfmsft_0-1651113370552.png     vkkfmsft_1-1651113385008.png

 

Then use the measure:

 

Measure = 
SWITCH (
    SELECTEDVALUE ( Slicer[Name] ),
    "Phone", SUM ( DB_Region[Phonesales] ),
    "Tablet", SUM ( DB_Region[Tabletsales] )
)

vkkfmsft_2-1651113569437.png

 

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.

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Syndicated - Outbound

Hi @Anonymous ,

 

I create the following sample data.

 

vkkfmsft_0-1651113370552.png     vkkfmsft_1-1651113385008.png

 

Then use the measure:

 

Measure = 
SWITCH (
    SELECTEDVALUE ( Slicer[Name] ),
    "Phone", SUM ( DB_Region[Phonesales] ),
    "Tablet", SUM ( DB_Region[Tabletsales] )
)

vkkfmsft_2-1651113569437.png

 

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.

vojtechsima
Super User
Super User

Syndicated - Outbound

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])
        )
)

 

 

 

avatar user
Anonymous
Not applicable

Syndicated - Outbound

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

Syndicated - Outbound

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])
        )
)
avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)