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
Unicorn_Tech
Resolver I
Resolver I

Countif Per Row, multiple values as grades

Hello.

 

I have about 20 fields of free text.  Each field has a corresponding "Grade", which is either Green, Yellow or Red (100000000, 100000001, 100000002). I want a column in Power BI, that will total all the "Greens" for the Row, and a column that will total all the "Reds" for the row, etc.

Ideally, for each row, we would then have totals of Green grades, Red grades, and Yellow grades.

It doesn't look like countx is suitable for this.

I would appreciate advice.  Thank you.

1 ACCEPTED SOLUTION

@Unicorn_Tech You want MC Aggregations: https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...

 

That said, you might considering unpivoting your columns as well as that tends to be a better format for analysis.


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

View solution in original post

4 REPLIES 4
v-luwang-msft
Community Support
Community Support

Hi @Unicorn_Tech ,

Try like below :

step1, create new table use following dax:

Table2 = CALCULATETABLE(DISTINCT('Table'[Column]))

Step2,then create new column:

Column 2 = IF('Table2'[Column]=100000000,"Green",IF('Table2'[Column]=100000001,"Yellow","Red")) 

 

Step 3, create the following measure:

Measure2 = var test=CALCULATE(COUNT('Table'[Column]),FILTER(ALL('Table'),'Table'[Column]=MAX(Table2[Column])))    RETURN  test
Measure3 = var test= SUMX(Table2,[Measure2])  return 
IF(HASONEVALUE(Table2[Column 2]),MAX(Table2[Column 2])&"="&test,"Total"&"="&test)

Final get :

vluwangmsft_0-1628146409989.png

 

Wish it is helpful for you!

 

Best Regards

Lucien

amitchandak
Super User
Super User

@Unicorn_Tech , can you share the expected output

you can have something like

example

A new column = sumx(Table, [Grade] = earlier([Grade]) , [Value])

 

A new Measure= sumx(allselected(Table), [Grade] = max([Grade]) , [Value])

My expected output:

I have 20 columns which either have the value of 100000000 or 100000001 or 100000002.

I expect the output to be:

Green = count of all 100000000 that appear within the row, across all columns.
Yellow= countof all 100000001 that appear within the row, across all the columns.
Red = count of all 100000002 that appear within the row, across all columns.

So a sample for a particular row:
Green = 15
Yellow = 2
Red = 3

@Unicorn_Tech You want MC Aggregations: https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...

 

That said, you might considering unpivoting your columns as well as that tends to be a better format for analysis.


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