March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi all,
I need some help with convert the below CASE statement to DAX query as a measure. Which should be able to execute in it's optimal perfomance state.
** I have mentioned the columns in the PBIX file for easier reference.
CASE WHEN
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]
IN ('1 - CURRENT ASSETS','2 - NON - CURRENT ASSETS')
THEN SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] )
ELSE SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1 END
Solved! Go to Solution.
NewMeasure=IF(MAX(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]) IN {"1 - CURRENT ASSETS","2 - NON - CURRENT ASSETS"},SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1)
or
NewMeasure=IF(SELECTEDVALUE(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]) IN {"1 - CURRENT ASSETS","2 - NON - CURRENT ASSETS"},SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1)
NewTable=ADDCOLUMNS(VALUES(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]),"Total",IF(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)] IN {'1 - CURRENT ASSETS','2 - NON - CURRENT ASSETS'},CALCULATE(SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] )),CALCULATE(SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] )) * -1))
@wdx223_Daniel Thank you very much for the quick response. Actually I need this to be used in a measure. So, how it should be changed? Sorry to bother you.
NewMeasure=IF(SELECTEDVALUE(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]) IN {'1 - CURRENT ASSETS','2 - NON - CURRENT ASSETS'},SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1)
Thank you very much @wdx223_Daniel. You have given measure works like a charm.
But the measure that you have been mentioned above returns the minus values instead of plus values. I understood it happened because of the value is multiplying from the minus 1.
I do have previously written measure by some other guy for the similar scenario. But it doesn't returns the minus values as the above measure. However, It takes much longer time to execute. Highly appreciate if you can please help me to improve the below measure on performance based and find the reason for not returning the minus values?
MEASURE FACT_CONSOL_BALANCE_OL[Measure 4] =
SWITCH (
TRUE (),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "1 - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "2 - NON - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1
)
NewMeasure=IF(MAX(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]) IN {"1 - CURRENT ASSETS","2 - NON - CURRENT ASSETS"},SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1)
or
NewMeasure=IF(SELECTEDVALUE(DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)]) IN {"1 - CURRENT ASSETS","2 - NON - CURRENT ASSETS"},SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.