Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 213819

DAX Measure with Nested IF Statements

$
0
0

Hey Everyone,

 

This is something that is relatively easy for me to figure out in other BI tools but I've had some issues with Power BI and DAX. Here is a sample table "Sales" :

  

Store NumberAdjustmentSales
1a4
1b2
1c6
2a4
2b8
2c7

 

What I want to do is show total Sales value and an Adjusted Sales value based on an Adjustment Rule.

 

The Adjustment Rule is as follows:

IF Adjustment =a then 100% of sales

IF Adjustment=b then 90% of sales

IF Adjustment=c then 50% of sales

 

So I want to have a table that has the total sales and adjusted sales:

Store NumberSalesAdjusted Sales
1128.8
21914.7
   

(i'm pretty sure I got the math right)

 

I started off with a dax statement in a calculated column that is something like:

IF(Adjustment="a", SUM(Sales),

     IF(Adjustment="b", SUM(Sales)*0.9,

     IF(Adjustment="c", SUM(Sales)*0.5,0

)))

 

But when it populated in Power BI it doesn't make sense at the row level. I think it was duplicating the values over all the rows so when I went to sum up all the adjusted sales it was exponentially more than the sales--- which according to the calculation it should be the same or less than the sales.  I think I need a measure but I noticed that I can't have string columns in measure statments.  How can I do this in DAX?

 

Thanks in advance,

 

Matt

 

 

 

 


Viewing all articles
Browse latest Browse all 213819

Trending Articles