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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

If then else in Power BI 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 Phone,Tablet and put in slicer

and I have region values coming from Region table

Now my requirement is


if Region='APAC' then it has to check another conditions

then if Slicervalue= 'Phone' then the calculation like sum(Phonesales),

then if Slicervalue= 'Tablet' then the calculation like sum(Tabletsales)

else if Region ='EMEA'

Slicervalue= 'Phone' then the calculation like sum(Phonesales),

Slicervalue= 'Tablet' then the calculation like sum(Tabletsales) ....

 

not sure how to write this in dax.

 

Could any one please help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Here's my solution.

1.Create a type table by entering data.

vstephenmsft_0-1651138110251.png

 

2.Create a measure to get the different kind of sales.

Sales = SWITCH(SELECTEDVALUE('Table (2)'[Type]),"Phone",SUM('Table'[PhoneSales]),"Tablet",SUM('Table'[TabletSales]))

 

When 'Phone' is selected,

vstephenmsft_1-1651138171915.png

When 'Tablet' is selected,

vstephenmsft_2-1651138189268.png

 

Best Regards,

Stephen Tao

 

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

5 REPLIES 5
PaulDBrown
Community Champion
Community Champion

Isn't the region Table linked to the sales table? If not, try:

 

_measure =
VAR _Device =
    SELECTEDVALUE ( DeviceTable[Device] )
VAR _Region =
    SELECTEDVALUE ( RegionTable[Region] )
RETURN
    SWITCH (
        TRUE (),
        AND ( _Region = "APAC", _Device = "Phone" ), SUM ( Table[PhoneSales] ),
        AND ( _Region = "APAC", _Device = "Tablet" ), SUM ( Table[TabletSales] ),
        AND ( _Region = "EMEA", _Device = "Phone" ), SUM ( Table[PhoneSales] ),
        AND ( _Region = "EMEA", _Device = "Tablet" ), SUM ( Table[TabletSales] )
    )

 

 

But bear in mind that unless there is a relationship between the region table and the sales table, you are going to get the same sales result by device type for both regions.

If there is a relationship between the region table and the sales table, all you need is:

_measure =
    SWITCH (
        SELECTEDVALUE ( DeviceTable[Device] ),
         "Phone" , SUM ( Table[PhoneSales] ),
        "Tablet" , SUM ( Table[TabletSales] )
)

 

It would help if you provided a depiction fo how the model is setup and how you expect to show the data in the visual





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Greg_Deckler
Community Champion
Community Champion

@Anonymous Here are some examples. Your requirements are not very clear.

Measure = 
  VAR __SlicerValue = SELECTEDVALUE('Table'[Column])
RETURN
  IF( 
    MAX('Table'[Region]) = "APAC",
    SWITCH(__SlicerValue,
      "Phone",SUM('Table'[Phonesales]),
      "Tablet",SUM('Table'[Tabletsales]),
    ),
        SWITCH(__SlicerValue,
      "Phone",SUM('Table'[Phonesales]),
      "Tablet",SUM('Table'[Tabletsales]),
    )
 )

Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
johnt75
Super User
Super User

It depends on how many regions you will need. If just 2 then you could do it with IF but it would probably be neater using a SWITCH statement

New Measure = SWITCH( TRUE(),
SELECTEDVALUE( 'Regions'[Region[]) = "APAC",
SWITCH( TRUE(),
SELECTEDVALUE( 'Table'[Slicer value] = "Phone", SUM(Phonesales[Amount]), 
SELECTEDVALUE( 'Table'[Slicer value] = "Table", SUM(Tabletsales[Amount])
),
SELECTEDVALUE( 'Regions'[Region[]) = "EMEA",
SWITCH( TRUE(),
SELECTEDVALUE( 'Table'[Slicer value] = "Phone", SUM(Phonesales[Amount]), 
SELECTEDVALUE( 'Table'[Slicer value] = "Table", SUM(Tabletsales[Amount])
)
)
Anonymous
Not applicable

Hi @johnt75 ,Greg_Deckler and  PaulDBrown,

 

This is my sample table data.

 

RegionPhoneSales TabletSales
APAC100200
APAC150250
EMEA8090
EMEA3040

 

I have region and sales coming from same table.

Now my requirement is I will put a slicer to end user which have values like phone ,Tablet

and put a filter on region  also

 

So If user selects slicer value phone then it has to show phone sales

similarly tablet then tablet sales.

 

So my condtion would be like this

 

if Region='APAC' then it has to check another conditions

then if Slicervalue= 'Phone' then the calculation like sum(Phonesales),

then if Slicervalue= 'Tablet' then the calculation like sum(Tabletsales)

else if Region ='EMEA'

Slicervalue= 'Phone' then the calculation like sum(Phonesales),

Slicervalue= 'Tablet' then the calculation like sum(Tabletsales) ....

 

Basically I will show one measure at a time based on slicer selection

 

Anonymous
Not applicable

Hi @Anonymous ,

 

Here's my solution.

1.Create a type table by entering data.

vstephenmsft_0-1651138110251.png

 

2.Create a measure to get the different kind of sales.

Sales = SWITCH(SELECTEDVALUE('Table (2)'[Type]),"Phone",SUM('Table'[PhoneSales]),"Tablet",SUM('Table'[TabletSales]))

 

When 'Phone' is selected,

vstephenmsft_1-1651138171915.png

When 'Tablet' is selected,

vstephenmsft_2-1651138189268.png

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors