Forum Discussion
SWITCH measures - sorting issue
- Anonymous1 year ago
Hi AndySmith,
I think your issue is based on your data model. Could you share a sample file with us and hsow us a screenshot with the result you want. This will make it easier for us to find the solution.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the reply. I get an error message saying that COALESCE is not a function and cannot be found? I am using a tabular model. Is that likely to make a difference?
Hi AndySmith -The COALESCE function was introduced in more recent versions of Power BI and SSAS (post-SQL Server 2016).
COALESCE not being recognized in your tabular model is likely because COALESCE is not supported in DAX within earlier versions of SQL Server Analysis Services (SSAS) Tabular Models.
you can try with iferror
Switch - Customer TimeFrame - Discount % =
VAR SelectedFrame = SELECTEDVALUE('Slicer - TimeFrame'[Select Time Frame], "MTD")
VAR DiscountResult =
SWITCH(
TRUE(),
SelectedFrame = "MTD", IFERROR([VE - Discount % MTD], 0),
SelectedFrame = "YTD", IFERROR([VE - Discount % FYTD], 0),
SelectedFrame = "MAT", IFERROR([VE - Discount % MAT], 0),
SelectedFrame = "Date Range", IFERROR([VE - Discount %], 0),
0
)
RETURN DiscountResult
or if isblank() function too
Switch - Customer TimeFrame - Discount % =
VAR SelectedFrame = SELECTEDVALUE('Slicer - TimeFrame'[Select Time Frame], "MTD")
VAR DiscountResult =
SWITCH(
TRUE(),
SelectedFrame = "MTD", IF(ISBLANK([VE - Discount % MTD]), 0, [VE - Discount % MTD]),
SelectedFrame = "YTD", IF(ISBLANK([VE - Discount % FYTD]), 0, [VE - Discount % FYTD]),
SelectedFrame = "MAT", IF(ISBLANK([VE - Discount % MAT]), 0, [VE - Discount % MAT]),
SelectedFrame = "Date Range", IF(ISBLANK([VE - Discount %]), 0, [VE - Discount %]),
0
)
RETURN DiscountResult