Forum Discussion
suman1985
2 years agoHelper I
Dax code help on Switch statement
Hi All, I am new to DAX, can you please verify my dax .I am trying to create measure which should group by year, and make SFDB value to null and then add sfdb value to Null value DAX: Meas...
- 2 years ago
hi suman1985
Measure 2 =VAR _Year = SELECTEDVALUE(TestTbl3[YEAR])VAR _Name = SELECTEDVALUE(TestTbl3[NAME])RETURNSWITCH( _Name,"SFDB", "","", CALCULATE( SUM(TestTbl3[AMOUNT]) , REMOVEFILTERS(TestTbl3), TestTbl3[YEAR] = _Year, TestTbl3[NAME] = "" || TestTbl3[NAME] = "SFDB"),SUM(TestTbl3[AMOUNT])) - Anonymous2 years ago
Hi suman1985 ,
talespin provides a good solution for you, while you can also try to follow my steps below:
Add two measures:1&0 = IF ( SELECTEDVALUE ( 'Table2'[NAME] ) = "" || SELECTEDVALUE ( 'Table2'[NAME] ) = "SFDB", 1, 0 )Measure_Expected Result = VAR _1 = CALCULATE ( SUM ( 'Table2'[AMOUNT] ), FILTER ( ALL ( 'Table2' ), 'Table2'[YEAR] = SELECTEDVALUE ( 'Table2'[YEAR] ) && 'Table2'[1&0] = 1 ) ) VAR _2 = IF ( SELECTEDVALUE ( 'Table2'[NAME] ) <> "", SELECTEDVALUE ( 'Table2'[AMOUNT] ), _1 ) RETURN IF ( SELECTEDVALUE ( 'Table2'[NAME] ) = "SFDB", "", _2 )Final output:
How to Get Your Question Answered Quickly - Microsoft Fabric Community
If it does not help, please provide more details with your desired out put and pbix file without privacy information.
Best Regards,
Ada Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- 2 years ago
Thank you so much it worked..Great help .
talespin
2 years agoSolution Sage
hi suman1985
Measure 2 =
VAR _Year = SELECTEDVALUE(TestTbl3[YEAR])
VAR _Name = SELECTEDVALUE(TestTbl3[NAME])
RETURN
SWITCH( _Name,
"SFDB", "",
"", CALCULATE( SUM(TestTbl3[AMOUNT]) , REMOVEFILTERS(TestTbl3), TestTbl3[YEAR] = _Year, TestTbl3[NAME] = "" || TestTbl3[NAME] = "SFDB"),
SUM(TestTbl3[AMOUNT])
)