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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
rippo
Regular Visitor

Add a column which is a sum (or percentage) of all rows

I have the following step in my power query

 

 

= Table.Group(Source, {"CountryName"}, {{"Count", each List.Sum([CountOf]), type number}})

 

 

This works great and returns this

 

2021-03-09_13-18-19.png

However I would like to create a third column which is either a total (sum) of all counts or even better a column showing a percentage of the current row against the total

 

Germany    914    7935
France      4203    7935

 

OR

Germany    914    11.5%
France      4203    52.9%

2 ACCEPTED SOLUTIONS
HotChilli
Super User
Super User

Add a custom column similar to this

List.Sum(#"Grouped Rows"[summ])

where #Grouped Rows is the previous query step and [summ] is the column to be summed.

 

You can get the % once you have this. 

View solution in original post

Jimmy801
Community Champion
Community Champion

Hello @rippo 

 

add a new column and paste this formula. ChangedType has to be replace with your last step

[Count]/List.Sum(ChangedType[Count])

Here the complete code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck8tyk3Mq1TSUbI0NFGK1YlWcitKzEtOBQqYGJkZgEWcMzLzEoEChuZGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CountryName = _t, Count = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"CountryName", type text}, {"Count", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(ChangedType, "%", each [Count]/List.Sum(ChangedType[Count]),Percentage.Type)
in
    #"Added Custom"

Jimmy801_0-1615381775914.png

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @rippo 

 

add a new column and paste this formula. ChangedType has to be replace with your last step

[Count]/List.Sum(ChangedType[Count])

Here the complete code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck8tyk3Mq1TSUbI0NFGK1YlWcitKzEtOBQqYGJkZgEWcMzLzEoEChuZGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CountryName = _t, Count = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"CountryName", type text}, {"Count", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(ChangedType, "%", each [Count]/List.Sum(ChangedType[Count]),Percentage.Type)
in
    #"Added Custom"

Jimmy801_0-1615381775914.png

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

HotChilli
Super User
Super User

Add a custom column similar to this

List.Sum(#"Grouped Rows"[summ])

where #Grouped Rows is the previous query step and [summ] is the column to be summed.

 

You can get the % once you have this. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors