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

Grouping based on conditions (segmentation)

Hi all,

 

I was looking online for conditional formatting, but mostly people use it to color a certain cell in there table.

But I want to use a few conditions to calculate a bonus. The bonus is as followed:

If value is lower than 8500, bonus is 0

If value is higher than 8500 and lower than 9000, bonus is 100

If value is higher than 9000, bonus is 150

 

To clarify, I have an excel file with the bonus min/max criteria and the value comes from another source.

Here's a picture to visualize it.

2.PNG

So I want to create a virtual table with the bonus amount based on the conditional formatting. 

 

EDIT: So far I'm using Countrows to create the virtual table. For now I only have 1 condition in this measure. But I'm not sure how to return specific values when it falls under a condition.

 

 

Bonus = 
COUNTROWS (
    FILTER( blad1, Blad1[Value] >= 9000 ) )

 

For example, here I would want to return 150.

But I also want < 8500 to return 0 and >= 8500 AND < 9000 to return 100. All in the same column. But is there a way to return a specific value? Or I'm I going wrong about this..

 

Thanks in advance!

1 ACCEPTED SOLUTION
Pragati11
Super User
Super User

Hi @Anonymous ,

 

You can achieve this by writing a conditional DAX IF statement. Try creating a calculated column as follows:

 

Bonus Calc = IF(tablename[Value] < 8500, 0, IF(tablename[Value] > 8500 && tablename[Value]  < 9000, 100, 150))

 

Try the above DAX and replace "tablename" with your table name in the baove formula.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

16 REPLIES 16
Anonymous
Not applicable

Hi @Pragati11 

 

I'm still having a problem. I'm using this measrement:

 

 

BonusTest = COALESCE(IF(SUM(Income[Value]) < SUM('BonusValues'[BonusMin]),0), IF(SUM(Income[Value]) < SUM('BonusValues'[BonusMax]), SUM('BonusValues'[BonusValueMin])), SUM('BonusValues'[BonusValueMax]))

 

 

But somehow, it's not adding everything up correctly. The conditions are working fine.

shockl1ne_1-1611147908354.png

 

But as you can see, the "total" value is incorrect. When I insert this function into a Calculated column, the total value is correct, but the conditions aren't working.. Can someone help me out on how to have the conditions working, as well as the total value?

Hi @Anonymous ,

 

You mentioned earlier that the last solution worked with calculated column as well as the measure that you came up with.

Now what is changed that it's not working? You current DAX is using COALESCE. Can you mention why this DAX is changed or is there any other requirement now?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

Hi, I looked at your solution some more, but in the future it's possible that the conditions or bonus values change. That's why I want to use for example an Excel sheet with these values. So that anyone can easily change the values, if needed. Currently I'm using this solution in a calculated column, and it seems to be working.. I changed the coalsece with calculate:

BonusC = CALCULATE(
        (if(sum(Income[Value])
        <sum('BonusValues'[BonusMin]),0, CALCULATE(if(sum(Omzetten[Value])
        <sum('BonusValues'[BonusMax]),sum('BonusValues'[BonusValueMin]),sum('BonusValues'[BonusValueMax]))))))

shockl1ne_0-1611148613965.png

I think this is an good solution. Sorry for ressurecting this post, I just found this out.. Do you see any improvements? This is a calculated Column and Parry mentioned that measures are better. Is this the same in this case? Or is a calculated column fine like this?

 

Hi @Anonymous ,

 

If you use the above exactly same DAX as a measure, it should work. Did you try it as a measure?

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

This is the result when I use it as a measure:

shockl1ne_0-1611149993193.png

The condition are working, but the total value is incorrect. 

Hi @Anonymous ,

 

Just refer this article for incorrect totals while using measure. This shows a way of making the totals right in a measure calculation.

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

@Pragati11 I want to expand my current function because there is another requirement. Would it be more appropiate to open a new thread? Since this one is about the conditional segmentation, which is now completed? 

Hi @Anonymous ,

 

Yes open a new thread. This will enable others as well to share their views.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

If I understand correctly, I should wrap my measure in HASONEFILTER ? The only thing I'm not sure in my case is, which column do I select? Because the measure itself is showing incorrect total value.. 

parry2k
Super User
Super User

@Anonymous sorry for jumping in here. I would avoid creating calculated columns where possible and try to create measures. Here is a amazing blog post talks about the difference between both.

 

Cheers!!

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi, I managed to use a measure:

BonusC = CALCULATE(
        (if(sum(Income[Value])
        <sum('BonusValues'[BonusMin]),0, CALCULATE(if(sum(Income[Value])
        <sum('BonusValues'[BonusMax]),sum('BonusValues'[BonusValueMin]),sum('BonusValues'[BonusValueMax]))))))

But it's not giving the correct total amount. Any reason why?

shockl1ne_0-1610723510300.png

 

Anonymous
Not applicable

Thanks for the tip, I'll look into it. Problem is, I could not get it to work using a measure..

Pragati11
Super User
Super User

Hi @Anonymous ,

 

You can achieve this by writing a conditional DAX IF statement. Try creating a calculated column as follows:

 

Bonus Calc = IF(tablename[Value] < 8500, 0, IF(tablename[Value] > 8500 && tablename[Value]  < 9000, 100, 150))

 

Try the above DAX and replace "tablename" with your table name in the baove formula.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

When I do that I get an error saying it can't find the column "Value" in the table "Bonus".. I tried something simular and had the same problem. It can only find another measure inside that Table..

This is the error:

A single value for the column 'Value' in the table 'Bonus' cannot be determined. This can occur if the measure's formula references a column that contains many values and no aggregation is specified as minimum, maximum, number, or sum to produce a single result.

This is the table:

shockl1ne_0-1610640417977.png

And this is the measure you suggested

shockl1ne_1-1610640449758.png

 

Hi @Anonymous ,

 

You are getting that error because you are creating a measure. I mentioned in my response that create a calculated column.

 

"Value" column I took in my DAX based on your screesnshot. Try replacing it with you actual column name in the data.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

Thanks a lot.. In a lot of online video's people are using measures for this purpose.. But what's the difference between a calculated column and a measure? I was trying the same with a measure but kept having that problem..

 

 

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.