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
BInovice
Frequent Visitor

Group data based on multiple conditions

All, I could use some help with this problem. I have a large table with "Mail type" and 'Delivery time" and I want to group the data or add a column retuning "Group" value based on the reference table below:

Mail typeDelivery time minDelivery time maxGroup
1st class14great
1st class57good
1st class8 bad
Priority13great
Priority46good
Priority7 bad
Express01great
Express23good
Express4 bad

 

What are my options?

 

Many thanks

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@BInovice So what are the rules? You could do something like:

Group =
  SWITCH(TRUE(),
    [Mail type] = "1st class" && [Delivery time max] <=4, "great",
    [Mail type] = "1st class" && [Delivery time max] <=7, "good",
    [Mail type] = "1st class" && [Delivery time max] >7, "bad",
    ...
  )
    


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

smpa01
Super User
Super User

@BInovice  you can write a measure like this

Measure =
VAR _mail =
    MAX ( t1[Mail type] )
VAR _time =
    MAX ( t1[Delivery time] )
VAR rating =
    CALCULATE (
        MAX ( t2[Group] ),
        FILTER ( t2, _time >= [Delivery time min] && _time <= [Delivery time max] ),
        TREATAS ( { _mail }, t2[Mail type] )
    )
RETURN
    IF ( ISBLANK ( rating ) = TRUE (), "bad", rating )

 

smpa01_0-1641331941154.png

 

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

@BInovice  you can write a measure like this

Measure =
VAR _mail =
    MAX ( t1[Mail type] )
VAR _time =
    MAX ( t1[Delivery time] )
VAR rating =
    CALCULATE (
        MAX ( t2[Group] ),
        FILTER ( t2, _time >= [Delivery time min] && _time <= [Delivery time max] ),
        TREATAS ( { _mail }, t2[Mail type] )
    )
RETURN
    IF ( ISBLANK ( rating ) = TRUE (), "bad", rating )

 

smpa01_0-1641331941154.png

 

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
Greg_Deckler
Community Champion
Community Champion

@BInovice So what are the rules? You could do something like:

Group =
  SWITCH(TRUE(),
    [Mail type] = "1st class" && [Delivery time max] <=4, "great",
    [Mail type] = "1st class" && [Delivery time max] <=7, "good",
    [Mail type] = "1st class" && [Delivery time max] >7, "bad",
    ...
  )
    


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thank you very much. It works great. I went for solution from smpa01 as that allows use to update the limits from separated table.

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.