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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
theaddies
Frequent Visitor

Use slicer value in conditional

I want to be able to populate the Category column depending on the values selected by the slicer.

 

Slicer 1

1, 2 or 3

Slicer 2

4, 5 or 6

 

ValueCategory
1

A

2A
3A
4B
5B
6C
7C
  

 

 

 

 

Category = 
var category_value_A = selectedvalue([Slicer 1])
var category_value_B = selectedvalue(Slicer 2])
return
switch(TRUE, [Value] <= category_value_A, "A",
       [Value] <= category_value_B, "B",
        "C")

 

 

I have tried the code above and it only works for the first condition and then exits the switch.

 

3 REPLIES 3
Anonymous
Not applicable

Hi  @theaddies ,

 

May I ask if your [Slicer1] and [Slicer2] are the following two columns?

vyangliumsft_0-1703050125898.png

Here are the steps you can follow:

1. Create measure.

 

Measure =
var category_value_A = MAXX(ALLSELECTED(Slicer_Table),[Slicer1])
var category_value_B = MAXX(ALLSELECTED(Slicer_Table),[Slicer2])
return
SWITCH(
    TRUE(),
    MAX('Table'[Value])<=category_value_A,"A",
    MAX('Table'[Value])>category_value_A&&MAX('Table'[Value])<=category_value_B,"B",
    "C")

 

2. Result:

vyangliumsft_1-1703050125898.png

 

Best Regards,

Liu Yang

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

Each slicer is a generated series.  The Maxx function does not work as it selects the final value in the series.

miTutorials
Super User
Super User

Try the below.

 

Category = 
var category_value_A = selectedvalue([Slicer 1])
var category_value_B = selectedvalue(Slicer 2])
return
switch(TRUE, [Value] <= category_value_A, "A",
       [Value] >= category_value_B, "B",
        "C")

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Kudoed Authors