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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
uxorise3424
Frequent Visitor

2 different formulas for conditional formatting based on different values

*I attached a sample file of data if looking at that before hand helps (it is very simple for privacy reasons, if you need more info i can add more

 

Table:

IDclassificationvalue
1focus4
1non-focus3
1non-focus5
1non-focus2
1non-focus4
1non-focus3
2focus4
2focus1
2focus2
2non-focus2
2non-focus3
2non-focus4
2non-focus4
3focus4
3focus5
3focus3
3non-focus4
3non-focus2
3non-focus1
3non-focus1
3non-focus3

 

So I am using a matrix for this data and want to add conditional formatting which I know how to do but struggling on changing it based on certain factors. 

 

While looking at the data you can see where ID = 1, there is only one focus in that section. When there is just one focus i want the conditional formatting to be if it is .3 or more than the focus then green, if .03 lower then red. This is very simple and would just be something like :

if average(query1[value]) .3 >= focus, 1, 2 and then i would do the conditional formatting as rules based on this measure and so on 

 

Then the second part is, in the sample data where ID = 2 or ID = 3, there are multiple focus's. When there is multiple focus's in an ID, I want the formatting to be the thing basically but .3 > than the average value for the ID rather than the focus. So this is basically the same formula but based on the averge vs the focus. 

 

My question is, how can I do this in the conditional formatting/ the measure for the conditional formatting. I dont know when an ID is going to have more than 1 focus so I can't just do IF ID = 3 then .3>averageid. 

 

I know how to explain it in words just not in a formula. Basically if an ID has > 1 focus then formula1, if not then formula2. If you have any tips on how to accomplish this, that would be great! Thanks 

3 REPLIES 3
v-cgao-msft
Community Support
Community Support

Hi @uxorise3424 ,

 

Please try:

Measure = 
VAR __CurrentID = MAX ( 'Table'[ID] )
VAR __FocusCount =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[ID] = __CurrentID,
        'Table'[classification] = "focus"
    )
VAR __Result = 
    IF(__FocusCount=1,<condition1>,<condition2>)
RETURN
__Result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

thanks i feel like this could work but i am having a small issue with it. So i have my two formulas for my conditional formatting and they work perfect individually but when I put them in this formula you gave me, they both completely change and not working right. I tried using the actual measure in the part where you put <condition1> and 2 and that didn't work. After that I used the formula from my measures and created a var in your formula and then used that in the condition and it didn't work either. Do you know why this would be?

edit: i realized it has to do with the count rows calcuation and it is always returning the secondc condition. i am looking into why this is happening

lbendlin
Super User
Super User

Your data is missing an index column.  Power BI will automatically aggregate unless you specifically tell it not to.

 

With the index the identification of your thresholds becomes easy.

 

lbendlin_0-1686015640161.png

 

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.