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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Switch statement issue

Hello Community:   I am trying to understand why the negative percent (discount) values are creeping into my table below.    I have this measure used in the chart below, and when I select the 20% or Less column, it is working correctly, however there are some negative percentages that show up in the table which is dynamically being filtered from the column chart.   

 

Is there something wrong with my SWITCH statement?

 

 

Discount Cohorts = SWITCH
(TRUE(),
'AllOpps-Products'[Discount]>=0.0 && 'AllOpps-Products'[Discount]<=.10,"10% or less",
'AllOpps-Products'[Discount]<=0.20,"20% or less",
'AllOpps-Products'[Discount]<=0.30,"30% or less",
'AllOpps-Products'[Discount]<=0.40,"40% or less",
'AllOpps-Products'[Discount]<=.50,"50% or less",
BLANK()
)

 

texmexdragon_0-1618765511048.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@HotChilli  That was a good tip and got me in the right direction.  Added a few more statements and perfecto.   This was the final measure that allowed for the correct grouping whether in a column chart or table. 

 

Discount Cohorts = IF(ISBLANK('AllOpps-Products'[Discount]),"Blank",
SWITCH
(TRUE(),
'AllOpps-Products'[Discount]< 0,"Negative %",
'AllOpps-Products'[Discount]>= 0.0000 && 'AllOpps-Products'[Discount]<.11,"0 to 10%",
'AllOpps-Products'[Discount]>= 0.11 && 'AllOpps-Products'[Discount]<.21,"11 to 20%",
'AllOpps-Products'[Discount]>= 0.21 && 'AllOpps-Products'[Discount]<0.31,"21 to 30%",
'AllOpps-Products'[Discount]>= 0.31 && 'AllOpps-Products'[Discount]<0.41,"31 to 40%",
'AllOpps-Products'[Discount]>= 0.41 && 'AllOpps-Products'[Discount]<.51,"41 to 50%",
'AllOpps-Products'[Discount]>= 0.51 && 'AllOpps-Products'[Discount]<=1.0,"51 to 100% ",
"Other"
))

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

Investigate which cohort negative discounts get assigned to.  

The easiest way is to add a table visual with discount and discount cohort. (as long as they don't aggregate).

Which cohort do you expect?

 

Anonymous
Not applicable

@HotChilli  That was a good tip and got me in the right direction.  Added a few more statements and perfecto.   This was the final measure that allowed for the correct grouping whether in a column chart or table. 

 

Discount Cohorts = IF(ISBLANK('AllOpps-Products'[Discount]),"Blank",
SWITCH
(TRUE(),
'AllOpps-Products'[Discount]< 0,"Negative %",
'AllOpps-Products'[Discount]>= 0.0000 && 'AllOpps-Products'[Discount]<.11,"0 to 10%",
'AllOpps-Products'[Discount]>= 0.11 && 'AllOpps-Products'[Discount]<.21,"11 to 20%",
'AllOpps-Products'[Discount]>= 0.21 && 'AllOpps-Products'[Discount]<0.31,"21 to 30%",
'AllOpps-Products'[Discount]>= 0.31 && 'AllOpps-Products'[Discount]<0.41,"31 to 40%",
'AllOpps-Products'[Discount]>= 0.41 && 'AllOpps-Products'[Discount]<.51,"41 to 50%",
'AllOpps-Products'[Discount]>= 0.51 && 'AllOpps-Products'[Discount]<=1.0,"51 to 100% ",
"Other"
))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.