The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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
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%
Solved! Go to Solution.
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.
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"
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
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"
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
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.