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

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

Reply
rsanyoto
Helper III
Helper III

Create range between two values with SWITCH

Hi all,

 

I would like to create a new column based on the margin value where some categories  need to be created so:
 Between 0 - 10000 , 10000 - 20000, 20000-30000, >30000

 

How would you to write the right measure ?

Capture.PNG

 
1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @rsanyoto ,

 

Incase you want to create a new Column,

 

New COLUMN =
SWITCH (
    TRUE (),
    'Table'[Margin] > 30000">30000",
    'Table'[Margin] <= 30000
        && 'Table'[Margin] > 20000" 20000-30000",
    'Table'[Margin] <= 20000
        && 'Table'[Margin] > 10000" 10000-20000",
    "Between 0-10000"
)

 

Regards,

Harsh Nathani

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

View solution in original post

4 REPLIES 4
harshnathani
Community Champion
Community Champion

Hi @rsanyoto ,

 

Incase you want to create a new Column,

 

New COLUMN =
SWITCH (
    TRUE (),
    'Table'[Margin] > 30000">30000",
    'Table'[Margin] <= 30000
        && 'Table'[Margin] > 20000" 20000-30000",
    'Table'[Margin] <= 20000
        && 'Table'[Margin] > 10000" 10000-20000",
    "Between 0-10000"
)

 

Regards,

Harsh Nathani

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

kentyler
Solution Sage
Solution Sage

Hello,

This is an example of the pattern called Parameter Table https://www.daxpatterns.com/parameter-table/

The basic approach is to create a table that holds your categories.

I made a small sample table categorytable.PNG

 

and some sample data  sampletable.PNG
and then I wrote my measures, following the Pattern
one to get the value to be categorized

Selected Value =
VAR current_value = SELECTEDVALUE('values'[value])
return current_value
One to get the Upper Boundary for each category
Upper Boundary = MAX(Categories[max])
One to get the Lower Boundary
Lower Boundary = Min(Categories[min])
And then a measure to figure out the category for the current row
In Category = CALCULATE(
MAX(Categories[category]),
FILTER(Categories,Categories[Lower Boundary] <= [Selected Value]),
FILTER(Categories,Categories[Upper Boundary] > [Selected Value])
)
 
because I do not have to do any calculation to get the value to be categorized I do not need to do a temporary table as is shown in the sample code for the Pattern


 
I created a short video explaining my solution https://www.youtube.com/watch?v=m6JJvoqLxNg



 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Great YouTube video with simply explanation! 

amitchandak
Super User
Super User

@rsanyoto , Refer if this can help

https://www.daxpatterns.com/dynamic-segmentation/

https://www.daxpatterns.com/static-segmentation/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors