Forum Discussion
List.Average and Select rows
Hi Anonymous
Thanks for the reply from amitchandak and danextian .
At present, the formula you use has to query the entire table for each row, that is, the entire table has to be queried as many times as there are rows. This may be the reason for the poor performance. I used Group By to test it for your reference. Using Group By can reduce the number of rows queried each time for calculation and improve performance, but the number of result rows obtained will definitely be less than the original table (each role will only get one row of results)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKsrPSTVU0lEyNFCK1UHiGsK5RqiyIK4pnGeMwbNQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ROLES = _t, WAGE = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ROLES", type text}, {"WAGE", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ROLES"}, {{"Average", each List.Average([WAGE]), type nullable number}})
in
#"Grouped Rows"
Output:
Best Regards,
Yulia Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello Anonymous,
thank you for your reply!
Unfortunately, I can not open your file.pbix, we have another version of PowerBi in company. Could you refer me what that code is doing? Too many new characters for me and I am kinda lost 🙂 Really apreciate your help.
- Anonymous1 year agoNot applicable
Hi Anonymous
#"Nested Join" = Table.NestedJoin(#"Grouped Rows", {"ROLES"}, #"Changed Type", {"ROLES"}, "Table", JoinKind.FullOuter)This step is to merge "Changed Type" and "Grouped Rows", which realizes the merging of the current query itself.
What is your Desktop version?
Best Regards,
Yulia Xu- Anonymous1 year agoNot applicable
Thanks,
so I added that formula to Power Bi, it did average, but it is going in turn
row1 is "role1" (in my original file it is 08001"
row2 is 08001
row3 is 08001
but it added to row1 role1, to row2 role2,...
and the formula created average
row1 - 10,5
row2 - 7,5
row3 - 6,5
the tables I sent are just example
ROLES WAGE AVG 08001 1000 1033,3333 08002 2000 2050 08001 900 1033,3333 08003 800 800 08001
1200 1033,0333 08002
2100 2050 and my file has many rows (thousands) and many variants of roles (hundreds)
I am using (i must use) 2.93.1681.0 64-bit (May 2021)