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
jonbox
Helper II
Helper II

Count cells with X background colour or X value

Hi, hopefully a quick one!

 

I'm trying to create a measure that count cells based on their colour.

 

This is my current measure which as i mentioned SHOULD count the number of green cells in july for each MAGICS scorecard area for each department,  e.g. for inventory (RM/PM/WIP) it should count 2. For inventory FP it should count 2. FOr ITOT it should count 0, as these are red, and i only want to count green.

 

Totals Dpt = COUNTX(filter(allselected('Scorecard (3)'), [Department] = MAX([Department]) && [Magics Scorecard Area] = MAX([Magics Scorecard Area])),[Jul Value])

 

jonbox_0-1635515050727.png

 

if this isn't possible, i also have another measure that uses an excel macro;

this macro represents the colours as numbers so that i can count that way, however i need a measure that count for department, for each magic scorecard area, each number represented as green, e.g. for department SYN, inventory (RM/PM/WIP) it should count two by counting the value in the Jul Value column.

jonbox_1-1635515421527.png

 

any help with this would be vastly appreciated! Thank you.

5 REPLIES 5
v-kelly-msft
Community Support
Community Support

Hi  @jonbox ,

 

Could you pls provide some sample data with expected output for test?

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

Hi @v-kelly-msft and @Greg_Deckler ,

 

Apologies for the delay with my reply;  

in terms of sample data and output and data;

 

IF the JULY SCORE meets the GOALS column e.g. first and third row, the cells are coloured green.

IF the JULY SCORE does not meet the GOALS column e.g. second and fourth row, the cells are coloured red.

 

In the July total, I want the cells to tally up the over all greens compared to reds e.g. in my sample, green cell means 1, red means 0.

 

In my previous example i didn't have the july score column but thinking about it logically, it would make sense to have it.

 

GoalsJuly ScoreJuly Total
0%0%1
0%10%0
> 95%99%1
100%50%0

 

Essentially i want it to count the number of greens and put it into a new column.

Hopefully that is clear and hope you can still help me with my issue!

 

Thanks a lot guys.

Hi  @jonbox ,

 

Using below M codes to get the column "July Total":

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlBV0oEQSrE6UK4hgh9TamBgnGppChKwtIQLGxqAlZhCFcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Goals = _t, #"July Score" = _t, #"July Total" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Goals", type text}, {"July Score", type text}, {"July Total", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Select([Goals],{"0".."9","%"})),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each let check=if Text.Length([Custom])<Text.Length([Goals]) then 1 else 0
in 
if check=1 then 
Text.Start([Goals],Text.Length([Goals])-Text.Length([Custom]))

else null),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if [Custom.1]=null then if Value.Compare(Number.From([July Score]),Number.From([Custom]))=0 then 1 else 0
else if Value.Compare(Number.From([July Score]),Number.From([Custom]))=1 then ">" else if Value.Compare(Number.From([July Score]),Number.From([Custom]))=0 then "=" else "<"),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom.3", each if [Custom.1]=null then [Custom.2] else if Text.Contains([Custom.2],[Custom.1]) then 1 else 0),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"July Total", "Custom.1", "Custom.2"})
in
    #"Removed Columns"

Then use color formatting to set the color of the value and you will see:

vkellymsft_0-1636535201766.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

Hi kelly,

 

thanks so much for the help. i've integrated your code into my powerbi and have it almost working, however the code seems to fail when picking up decimal numbers in particular? 

 

As you can see below the "custom" column converts to 095 rather than 0.95 . assume that has something to do with it? although custom.2 seems to understand that the Jul column is greater than the goals column, so why does it show as 0 in custom.3?

 

Any help with this please?

 

jonbox_0-1636729784759.png

 

Thanks again for your help

Greg_Deckler
Super User
Super User

@jonbox This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.

 

If that doesn't help, would need sample data as text. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.