The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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)
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.