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
adavid999
Helper V
Helper V

custom column with M calculating % with null values

Hello,

In power query, how might I create a custom column "% column" where there are also null values in my reference columns A, B and C.

Without null values, it's straightforward. For row 1 I could write =([A]+[B]+[C])/3. However, what can I do where there are null values? Row 2 would be [A]+[B]/2 And Row 3 would be [B]+[C]/2

 

ID% columnABC
166110
25010null
3100null11

Many thanks,

A

1 ACCEPTED SOLUTION

Hi, @adavid999 

It is difficult to create the custom columns if you want based on your current table structure.

You can try the following steps in the query editor:

1.select columns  "A","B","C" ->unpivot columns (generate new columns "Attribute","Value")

103.png

2.Group by as below

104.png

3.create Custom column"Result Percentage%" as below:

 

=[#"Sum value (by ID)"]/[#"Count Rows (by ID)"]

 

106.png

4.Expand table and delete unnecessary columns

107.png

108.png

5.select columns"Attribute" ,"Value" ->pivote column

109.png

Result will show as below:

111.png

Please check my sample pbix for more details.

 

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
adavid999
Helper V
Helper V

Thank you for replying. Your proposed solution looks useful but I would like a solution in M that can create the custom column if possible.

Hi, @adavid999 

It is difficult to create the custom columns if you want based on your current table structure.

You can try the following steps in the query editor:

1.select columns  "A","B","C" ->unpivot columns (generate new columns "Attribute","Value")

103.png

2.Group by as below

104.png

3.create Custom column"Result Percentage%" as below:

 

=[#"Sum value (by ID)"]/[#"Count Rows (by ID)"]

 

106.png

4.Expand table and delete unnecessary columns

107.png

108.png

5.select columns"Attribute" ,"Value" ->pivote column

109.png

Result will show as below:

111.png

Please check my sample pbix for more details.

 

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi, @adavid999 

Please correct me if I wrongly understood your question.

I suggest unpivoting the table like below in Power Query Editor.

 

Picture1.pngPicture2.png

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: https://www.linkedin.com/in/jihwankim1975/

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.