Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
AndySmith
Helper III
Helper III

SWITCH measures - sorting issue

I have a few switch measures in order to toggle between various time frame calcs for customer sales (MTD, YTD and MAT). They seem to calculate correctly, but if I try to sort by the Sales value measure, the Discount % calculations dissapear. Any ideas why this might be or how to get around it? User will want/need to sort by both columns . Thanks.

 

AndySmith_0-1729471053709.png 

AndySmith_1-1729471067735.png

 

 

Switch - Customer TimeFrame - Wsale =
VAR SelectedFrame = SELECTEDVALUE('Slicer - TimeFrame'[Select Time Frame], "MTD")
VAR WsaleValue =
    SWITCH(
        TRUE(),
        SelectedFrame = "MTD", CALCULATE([VE - Wholesale Amt MTD]),
        SelectedFrame = "YTD", CALCULATE([VE - Wholesale Amt FYTD]),
        SelectedFrame = "MAT", CALCULATE([VE - Wholesale Amt MAT]),
        CALCULATE([VE - Wholesale Amt])  
    )
RETURN
    WsaleValue  
 
Switch - Customer TimeFrame - Discount % =
VAR SelectedFrame = SELECTEDVALUE('Slicer - TimeFrame'[Select Time Frame], "MTD")
VAR DiscountResult =
    SWITCH(
        TRUE(),
        SelectedFrame = "MTD", [VE - Discount % MTD],
        SelectedFrame = "YTD", [VE - Discount % FYTD],
        SelectedFrame = "MAT", [VE - Discount % MAT],
        SelectedFrame = "Date Range", [VE - Discount %],
        0  
    )
RETURN DiscountResult

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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 Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
AndySmith
Helper III
Helper III

Thanks again! Sadly still no luck. There are definitley times when there are no discounts but that shouldnt matter for the measure. Everything calculates perfectly well then the disc % just disappears when i try to sort  

AndySmith_0-1729483766273.png

 

Anonymous
Not applicable

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 Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Rico

I think it may be the model. Is tabular model but there are blank rows when i bring in every dimension such as customer or product etc. Will consult with the IT team. 

AndySmith
Helper III
Helper III

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?

  

AndySmith_0-1729480685881.png

 

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





rajendraongole1
Super User
Super User

Hi @AndySmith - please find the modified measure for %

Switch - Customer TimeFrame - Discount % =
VAR SelectedFrame = SELECTEDVALUE('Slicer - TimeFrame'[Select Time Frame], "MTD")
VAR DiscountResult =
SWITCH(
TRUE(),
SelectedFrame = "MTD", CALCULATE([VE - Discount % MTD]),
SelectedFrame = "YTD", CALCULATE([VE - Discount % FYTD]),
SelectedFrame = "MAT", CALCULATE([VE - Discount % MAT]),
SelectedFrame = "Date Range", CALCULATE([VE - Discount %]),
0
)
RETURN DiscountResult

 

common cause for disappearing values when sorting is the presence of blank values in the measure.

Switch - Customer TimeFrame - Discount % =
VAR SelectedFrame = SELECTEDVALUE('Slicer - TimeFrame'[Select Time Frame], "MTD")
VAR DiscountResult =
SWITCH(
TRUE(),
SelectedFrame = "MTD", COALESCE([VE - Discount % MTD], 0),
SelectedFrame = "YTD", COALESCE([VE - Discount % FYTD], 0),
SelectedFrame = "MAT", COALESCE([VE - Discount % MAT], 0),
SelectedFrame = "Date Range", COALESCE([VE - Discount %], 0),
0
)
RETURN DiscountResult

 

check with the above measure, hope it works in your scenerio





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors