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.
Here is my data columns, i need to find the % for each individual, (so for each name total the amount then take individual values and divide by total) but I need the Name column and the Ordered2023 column..
i am trying to figure how to add a total column for each name but cant figure it out, any suggestions?
currently i have a second duplicate table, groupby name that gives me the total, i merge the total to original data table above, then do the division.... wondering if there is another more efficient way to do it without the need to add a table to get totals.
thanks
Solved! Go to Solution.
Hi,
A solution with Group and Expand.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzALCcgyxTOsoCzLMEsZ7gOZ7gOEMtEKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t, Count = _t]),
Type = Table.TransformColumnTypes(Source,{{"Count", type number}}),
Group = Table.Group(Type, {"Names"}, {{"Sum", each List.Sum([Count])}, {"Count", each [Count]}}),
Expand = Table.ExpandListColumn(Group, "Count"),
Percentage = Table.AddColumn(Expand, "%", each [Count] / [Sum], Percentage.Type)
in
Percentage
or with ExpandTableColumn
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzALCcgyxTOsoCzLMEsZ7gOZ7gOEMtEKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t, Count = _t]),
Type = Table.TransformColumnTypes(Source,{{"Count", type number}}),
Group = Table.Group(Type, {"Names"}, {{"Sum", each List.Sum([Count])}, {"Data", each _}}),
Expand = Table.ExpandTableColumn(Group, "Data", {"Count"}, {"Count"}),
Percentage = Table.AddColumn(Expand, "%", each [Count] / [Sum], Percentage.Type)
in
Percentage
Stéphane
Hi,
A solution with Group and Expand.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzALCcgyxTOsoCzLMEsZ7gOZ7gOEMtEKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t, Count = _t]),
Type = Table.TransformColumnTypes(Source,{{"Count", type number}}),
Group = Table.Group(Type, {"Names"}, {{"Sum", each List.Sum([Count])}, {"Count", each [Count]}}),
Expand = Table.ExpandListColumn(Group, "Count"),
Percentage = Table.AddColumn(Expand, "%", each [Count] / [Sum], Percentage.Type)
in
Percentage
or with ExpandTableColumn
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWBsIzALCcgyxTOsoCzLMEsZ7gOZ7gOEMtEKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t, Count = _t]),
Type = Table.TransformColumnTypes(Source,{{"Count", type number}}),
Group = Table.Group(Type, {"Names"}, {{"Sum", each List.Sum([Count])}, {"Data", each _}}),
Expand = Table.ExpandTableColumn(Group, "Data", {"Count"}, {"Count"}),
Percentage = Table.AddColumn(Expand, "%", each [Count] / [Sum], Percentage.Type)
in
Percentage
Stéphane
You can do it in the same query by creating a 2nd table of the group by, but you will still need to merge.
I would step back and ask why are you doing this in Power Query. Getting % of total is usually best done in the DAX side which is optimized for those types of operations. Power Query isn't. Even if you get it to work, and you definitely can, the larger the dataset the slower it becomes until Power Query won't be able to finish.
Power Query is horrible at table scans, and not great at analysis in general. It is best suited for transforming data so the Power BI model can best analyze it with DAX.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingCovering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.