Forum Discussion
Anonymous
6 years agoNot applicable
Calculating average in rows rather than as column
Hi there, I have been searching for a solution to my problem, but unfortunately without luck. My dataset consists of monthly prices for 4 companies. What I would like to do is to calculate th...
- 6 years ago
Hi Anonymous ,
You could try below M code to see whether it work or not
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcyxDcAwDAPBXVQbsEU5WcZQm/1HiFURApsvvrhzDAtr+nQb9lXccvSLG8iNm5C7bzYv6EIuugC6KpT78AbdkIsuBF0Vyn0t8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Company = _t, Return = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Company", type text}, {"Return", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Return", each List.Average([Return]), type number}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Company", each "Benchmark"), #"Appended Query" = Table.Combine({#"Added Custom", #"Changed Type"}) in #"Appended Query"Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
dax
6 years agoCommunity Support
Hi Anonymous ,
You could try below M code to see whether it work or not
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcyxDcAwDAPBXVQbsEU5WcZQm/1HiFURApsvvrhzDAtr+nQb9lXccvSLG8iNm5C7bzYv6EIuugC6KpT78AbdkIsuBF0Vyn0t8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Company = _t, Return = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Company", type text}, {"Return", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Return", each List.Average([Return]), type number}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Company", each "Benchmark"),
#"Appended Query" = Table.Combine({#"Added Custom", #"Changed Type"})
in
#"Appended Query"
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Thanks dax, works a charm