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
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
v-yangliu-msft
Community Support
Community Support

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
v-yangliu-msft
Community Support
Community Support

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
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.