Forum Discussion
MWinter225
Advocate IV
9 years agoDAX Measure with Nested IF Statements
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 Numbe...
- 9 years ago
MWinter225If you do want Measures - these should work also! :smileyhappy:
MEASURE 1
Total Adj Sales ALT = SUMX ( 'Table', IF ( 'Table'[Adjustment] = "b", 'Table'[Sales] * 0.9, IF ( 'Table'[Adjustment] = "c", 'Table'[sales] * 0.5, 'Table'[Sales] ) ) )MEASURE 2 - SWITCH is internally converted into nested IFs - one thing I really like is that its much easier to read and write
Total Adj Sales ALT 2 = SUMX ( 'Table', SWITCH ( TRUE (), 'Table'[Adjustment] = "b", 'Table'[Sales] * 0.9, 'Table'[Adjustment] = "c", 'Table'[sales] * 0.5, 'Table'[Sales] ) )Now you have 3 options which should all give you the same result!
Good Luck! :smileyhappy:
Sean
Community Champion
9 years agoMWinter225If you do want Measures - these should work also! :smileyhappy:
MEASURE 1
Total Adj Sales ALT =
SUMX (
'Table',
IF (
'Table'[Adjustment] = "b",
'Table'[Sales] * 0.9,
IF ( 'Table'[Adjustment] = "c", 'Table'[sales] * 0.5, 'Table'[Sales] )
)
)MEASURE 2 - SWITCH is internally converted into nested IFs - one thing I really like is that its much easier to read and write
Total Adj Sales ALT 2 =
SUMX (
'Table',
SWITCH (
TRUE (),
'Table'[Adjustment] = "b", 'Table'[Sales] * 0.9,
'Table'[Adjustment] = "c", 'Table'[sales] * 0.5,
'Table'[Sales]
)
)Now you have 3 options which should all give you the same result!
Good Luck! :smileyhappy:
jubrna01
8 years agoFrequent Visitor
This solved my problem, thanks :)