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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
CaveOfWonders
Helper IV
Helper IV

RAG Logic Based on Group for a new column

Dear Community

 

Not sure how to do the following. I have a table with a location column, a main category column, a subcategory column and a rag status:

 

LocationMain CategorySub CategoryRAGExpected Ouput
HomeaaRedRed
HomeaaGreenRed
HomeabAmberRed
HomeabAmberRed
HomeacGreenRed
HomeacGreenRed
AwaybaAmberAmber
AwaybaAmberAmber
AwaybbAmberAmber
AwaybbAmberAmber
AwaybcGreenAmber
AwaybcGreenAmber
WorkcaGreenGreen
WorkcaGreenGreen
WorkcbAmberGreen
WorkcbAmberGreen
WorkccGreenGreen
WorkccGreenGreen

 

I need to apply the following logic to get an overall rag status for the location and main category:

 

- Red Score: When a red KPI exists in a group of KPIs
- Amber Score: If there are more amber than green (No Red)
- Green Score: If there are more green than amber (No Red)

 

My expected result is:

 

CaveOfWonders_0-1621331587653.png

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @CaveOfWonders  ,
Here are the steps you can follow:

1. Create measure.

Expected Output =
var _countred=CALCULATE(COUNT('Table'[RAG]),FILTER(ALL('Table'),'Table'[Location]=MAX('Table'[Location])&&'Table'[RAG]="Red"))
var _countamber=CALCULATE(COUNT('Table'[RAG]),FILTER(ALL('Table'),'Table'[Location]=MAX('Table'[Location])&&'Table'[RAG]="Amber"))
var _countgreen=CALCULATE(COUNT('Table'[RAG]),FILTER(ALL('Table'),'Table'[Location]=MAX('Table'[Location])&&'Table'[RAG]="Green"))
return
SWITCH(
    TRUE(),
    _countred<>0,"red",
    _countred=0&&_countgreen>_countamber,"Green",
    _countred=0&&_countgreen<_countamber,"Amber")
color =
SWITCH(
    TRUE(),
    [Expected Output]="red","red",
    [Expected Output]="Green","Green",
    [Expected Output]="Amber","#FFBF00")

2. Select the [Expected Output] column and click Conditional formatting – Background color

v-yangliu-msft_0-1621486189342.png

3. Enter the Background color interface, select Format by – Field value, Base on field – measure[color]

v-yangliu-msft_1-1621486189345.png

4. Result.

v-yangliu-msft_2-1621486189348.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.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @CaveOfWonders  ,
Here are the steps you can follow:

1. Create measure.

Expected Output =
var _countred=CALCULATE(COUNT('Table'[RAG]),FILTER(ALL('Table'),'Table'[Location]=MAX('Table'[Location])&&'Table'[RAG]="Red"))
var _countamber=CALCULATE(COUNT('Table'[RAG]),FILTER(ALL('Table'),'Table'[Location]=MAX('Table'[Location])&&'Table'[RAG]="Amber"))
var _countgreen=CALCULATE(COUNT('Table'[RAG]),FILTER(ALL('Table'),'Table'[Location]=MAX('Table'[Location])&&'Table'[RAG]="Green"))
return
SWITCH(
    TRUE(),
    _countred<>0,"red",
    _countred=0&&_countgreen>_countamber,"Green",
    _countred=0&&_countgreen<_countamber,"Amber")
color =
SWITCH(
    TRUE(),
    [Expected Output]="red","red",
    [Expected Output]="Green","Green",
    [Expected Output]="Amber","#FFBF00")

2. Select the [Expected Output] column and click Conditional formatting – Background color

v-yangliu-msft_0-1621486189342.png

3. Enter the Background color interface, select Format by – Field value, Base on field – measure[color]

v-yangliu-msft_1-1621486189345.png

4. Result.

v-yangliu-msft_2-1621486189348.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.

Thank you so so much. You are a star

 

CaveOfWonders
Helper IV
Helper IV

Is it possible to create a measure for this?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors