Forum Discussion
Dax code help on Switch statement
- 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 .
hi suman1985
- suman19852 years agoHelper I
Thank you so much it worked..Great help .
- h16292 years agoFrequent Visitor
I have a similar case where I am creating measure for Power BI Data model. Where I need to filter the fact tables and dim tables in the measure. This measure should work if end users wants to see year in the table or year month.
- talespin2 years agoSolution Sage
hi h1629 ,
You can use this, replace with your table name and column names.
MSales =VAR _Name = SELECTEDVALUE(DimProductCategory[EnglishProductCategoryName])RETURNSWITCH( _Name,"Bikes", 0,"Accessories",CALCULATE([MSalesAmount] ,REMOVEFILTERS(DimProductCategory[EnglishProductCategoryName]),DimProductCategory[EnglishProductCategoryName] = "Bikes" || DimProductCategory[EnglishProductCategoryName] = "Accessories",Isrelevant = "Y", Indexragge > 2),[MSalesAmount])
- h16292 years agoFrequent Visitor
Thank you it worked for me. Great work.