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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
k1s2
Helper I
Helper I

Count number of times specific value appears in each row across columns whose name contains

How do I count the number of times the cell value = "High" across column names ending with the text "Rating"?

 

I think the column filter could be done with something like

 

List.Transform(List.Select(Table.ColumnNames(source), eachText.EndsWith(_,"Rating")))

 

...but no idea how to count across them.

 

  

1 ACCEPTED SOLUTION
spinfuzer
Solution Sage
Solution Sage

You can add a custom column with a formula like below.

[ 
    a = List.Select(Record.FieldNames(_), (x) => Text.EndsWith(x, "Rating")),
    b = Record.SelectFields(_,a),
    c = List.Count(List.Select(Record.FieldValues(b), (x) => x = "High"))
][c]

View solution in original post

3 REPLIES 3
k1s2
Helper I
Helper I

Thanks - that seems to work nicely.  Do you have time to explain how it works?

In particular, the (x) => is a mystery to me

Take any custom column you have created before.

Say something like =[Column1]

You'll notice in your code you got something like each [Column1].  each is a function.

 

each [Column1] is the same as (_) => _[Column1].  It is called syntax sugar and it is a way to make code look cleaner where possible.  You will notice in any custom column you create, you can put an underscore in front of the colum names and you will get the same result (e.g. type _[Column1] and you'll get the same result as just [Column1]).

 

Alternatively, instead of each [Column1], you could type it as (a) => a[Column1] and you'd get the same result, but you must type a in front of Column1 in this case.  When you use each, the underscore is optional.

 

 

Since the each function has already been used and refers to the elements in the current row, you need to define a different function to refer to the elements in the current list if you a function parameter (e.g. List.Select's 2nd parameter is selector as function).

 

https://learn.microsoft.com/en-us/powerquery-m/list-select

 

 

 

spinfuzer
Solution Sage
Solution Sage

You can add a custom column with a formula like below.

[ 
    a = List.Select(Record.FieldNames(_), (x) => Text.EndsWith(x, "Rating")),
    b = Record.SelectFields(_,a),
    c = List.Count(List.Select(Record.FieldValues(b), (x) => x = "High"))
][c]

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors