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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count and sum at row level

 

Hi,

Sorry, I am NOT a dax type person and am going crazy with sum, count etc.....

 

As per excel demo, I just want to count per row and get the result like in excel....... Any help would be welcomed!

 

PBI Simple count.PNG

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Here is a method with Power Query, not DAX. You can add a custom column with below code. Hope it helps. 

 

List.NonNullCount(Record.ToList(_))

 

vjingzhang_0-1663912184433.png

 

For sum, you can replace List.NonNullCount with List.Sum.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Here is a method with Power Query, not DAX. You can add a custom column with below code. Hope it helps. 

 

List.NonNullCount(Record.ToList(_))

 

vjingzhang_0-1663912184433.png

 

For sum, you can replace List.NonNullCount with List.Sum.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Anonymous
Not applicable

Thanks very much, thats opended my eyes to some new logic..... However, could you outline the purpose of the _ in the brackets? i.e. I can generally follow a query/formula, but this one has got me guessing? The formula worked, but just embedding it further with a slight tweak on this building block (to the data). Can the same logic be used to exlcude the first column master?

 

i.e. this is essentially a realtional merge, where MASTER is the primany key, with 3 tables linked to it.

 

See above, I just added a "-1" in brackets and it removes the count of one I want to exlclude (its a constant, so no issues for me)

 

Tweak.PNG

Hi @Anonymous 

 

Use this

List.NonNullCount(Record.ToList(Record.RemoveFields(_,{"master"})))

 

Best Regards,
Community Support Team _ Jing

Hi @Anonymous 

 

Well, "_" is a magic in Power Query I think. I don't know how to explain it clearly. It represents each expression in its environment. So it can be any type of value according to where it is. 

 

In the current sample, "_" represents every row. You can add a custom column with only "_". Just like below image. "_" is a record which contains all pairs of column name & column value in the current row. 

vjingzhang_0-1663919568971.png

 

There is a simple explanation of "_" in Simplified declarations section in this official document  M Language Functions - PowerQuery M. However it is too simple to make it clear enough to new users. You need to test it more in different kinds of functions to learn about it.

 

For example, when you transform Age column to add 1 to it, you will find "_" appear in the auto-generated step. Here it represents the value in Age column on each row. 

vjingzhang_1-1663920019034.png

 

Try more, you will find Power Query interesting!

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors