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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
nbs33
Helper II
Helper II

Error using conditional logic in switch function

Hi,

I am trying to create buckets of customers based on % change YTD vs PYTD revenue. I only want to group negative values.  I am getting strange results where all my negative values in my table are showing “< -30%”.  Does anyone know what error I am making?

TEST Bucket = 
VAR testCondition = DIVIDE([YTD vs PYTD Revenue],[PYTD Revenue],0)

RETURN
SWITCH(
    TRUE(),
    testCondition<= 0 && testCondition> -30, "< -30%",
    testCondition<= -30 && testCondition> -40,"-30% to -39%",
    testCondition<= -40 && testCondition> -50,"-40% to -49%",
    testCondition<= -50 && testCondition> -60,"-50% to -59%",
    testCondition<= -60 && testCondition> -70,"-60% to -69%",
    testCondition<= -70 && testCondition> -80,"-70% to -79%",
    testCondition<= -80 && testCondition> -90,"-80% to -89%",
    testCondition<= -90 && testCondition> -100,"-90% to -100%"
)

 

https://drive.google.com/file/d/1IjPb5BjE8eiqIqTHInvOYzuWh8QDtZ5S/view?usp=sharing

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@nbs33  can you try this

 

TEST Bucket = 
VAR testCondition = DIVIDE([YTD vs PYTD Revenue],[PYTD Revenue],0)

RETURN
SWITCH(
    TRUE(),
	testCondition> -100&&testCondition<= -90,"-90% to -100%",
	testCondition> -90&&testCondition<= -80,"-80% to -89%",
	testCondition> -70&&testCondition<= -60,"-70% to -79%"
	--------------------------------------------------------
	--------------------------------------------------------
	testCondition> -30&&testCondition<= 0,"0 to -30%")
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

3 REPLIES 3
smpa01
Super User
Super User

@nbs33  did you try this yet?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
smpa01
Super User
Super User

@nbs33  can you try this

 

TEST Bucket = 
VAR testCondition = DIVIDE([YTD vs PYTD Revenue],[PYTD Revenue],0)

RETURN
SWITCH(
    TRUE(),
	testCondition> -100&&testCondition<= -90,"-90% to -100%",
	testCondition> -90&&testCondition<= -80,"-80% to -89%",
	testCondition> -70&&testCondition<= -60,"-70% to -79%"
	--------------------------------------------------------
	--------------------------------------------------------
	testCondition> -30&&testCondition<= 0,"0 to -30%")
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01 this worked! The just had to change the values to decimal form and it worked perfectly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.