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
flanshaw
Helper I
Helper I

Count number of multiple non-blank fields in a row

Hi, I have a data set that for every row has 20 procedure codes ie.

name, proc1,proc2,proc3,proc4,proc5,......,proc20

JR,H123, H321, ,, ,,, , 

 

the data set has around 1.2 million rows

 

Im trying to figure out how to create a custom column that adds up the number of fields per row that are not blank, on a row by row basis.

ie in the example above, the custom column would equal 2, as there are 2 procedure codes with non-blank entries

 

or another example:

DS, J123,U7345,P344,T546, , , , , , , ..... would equal 4

 

thanks

 

Any thoughts - is there  a DAX function that would do this for me.

2 ACCEPTED SOLUTIONS
v-huizhn-msft
Employee
Employee

@flanshaw

From what I know, I find two solution to solve your issue. I test it using the name have 10 products rather than 20 products.

On the one hand, if the name row is unique, please create a calculated column using the following formula to get expected result.

 

Result = IF(ISBLANK(Table6[proc1]),0,1)+IF(ISBLANK(Table6[proc2]),0,1)+IF(ISBLANK(Table6[proc3]),0,1)+IF(ISBLANK(Table6[proc4]),0,1)+IF(ISBLANK(Table6[proc5]),0,1)+IF(ISBLANK(Table6[proc6]),0,1)+IF(ISBLANK(Table6[proc7]),0,1)+IF(ISBLANK(Table6[proc8]),0,1)+IF(ISBLANK(Table6[proc9]),0,1)+IF(ISBLANK(Table6[proc10]),0,1)

 1.png

On the other hand, please use Unpivot Columns and Group by function in Power Query. You can transform selected columns into attribute-value pairs where columns become rows using “Unpivot Columns”. And aggregate row when select group by.

You can refer to below operation to get what you want.

1. I create the following sample data. Right Click->Edit Query, we will get the Edit Query interface in second screenshot.

 

2.png

3.png

2. Select the first column (name), on the Ribbon Transform, click on Unpivot Columns > Unpivot Other Columns(highlighted in yellow as follows). From the result, the first column is name, the second is the product type, and the third is the value of each type product, it will elliptic if the value is null.

4.png  5.png

3. Click the Group By, enter the name and select right operation, it will aggregate according to name like below screenshot.

5.png

4. Click OK, you will get the expected result. Click close and apply. The table will be changed based on operation. The first picture display the expected result in Edit Query, and the second picture displays the result table in PowerBI desktop.

1.jpg.png

333.PNG


For more details, please review the article. If you have any question, please feel free to ask.


Best Regards,
Angelia

View solution in original post

Great stuff. Works a treat using the first method. thank you.

View solution in original post

3 REPLIES 3
v-huizhn-msft
Employee
Employee

@flanshaw

From what I know, I find two solution to solve your issue. I test it using the name have 10 products rather than 20 products.

On the one hand, if the name row is unique, please create a calculated column using the following formula to get expected result.

 

Result = IF(ISBLANK(Table6[proc1]),0,1)+IF(ISBLANK(Table6[proc2]),0,1)+IF(ISBLANK(Table6[proc3]),0,1)+IF(ISBLANK(Table6[proc4]),0,1)+IF(ISBLANK(Table6[proc5]),0,1)+IF(ISBLANK(Table6[proc6]),0,1)+IF(ISBLANK(Table6[proc7]),0,1)+IF(ISBLANK(Table6[proc8]),0,1)+IF(ISBLANK(Table6[proc9]),0,1)+IF(ISBLANK(Table6[proc10]),0,1)

 1.png

On the other hand, please use Unpivot Columns and Group by function in Power Query. You can transform selected columns into attribute-value pairs where columns become rows using “Unpivot Columns”. And aggregate row when select group by.

You can refer to below operation to get what you want.

1. I create the following sample data. Right Click->Edit Query, we will get the Edit Query interface in second screenshot.

 

2.png

3.png

2. Select the first column (name), on the Ribbon Transform, click on Unpivot Columns > Unpivot Other Columns(highlighted in yellow as follows). From the result, the first column is name, the second is the product type, and the third is the value of each type product, it will elliptic if the value is null.

4.png  5.png

3. Click the Group By, enter the name and select right operation, it will aggregate according to name like below screenshot.

5.png

4. Click OK, you will get the expected result. Click close and apply. The table will be changed based on operation. The first picture display the expected result in Edit Query, and the second picture displays the result table in PowerBI desktop.

1.jpg.png

333.PNG


For more details, please review the article. If you have any question, please feel free to ask.


Best Regards,
Angelia

Great stuff. Works a treat using the first method. thank you.

BhaveshPatel
Community Champion
Community Champion

May be THIS could be some help to you

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

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.