Forum Discussion
Anonymous
3 years agoNot applicable
Geometric Mean for Grouped Data
Hello Team, Could you please help me with this I want to get the GeoMean for below example. I have groped data and I want to creat a cutom column that calculate a the Geometric Mean for the Durat...
- 3 years ago
Hi Anonymous ,
I would recommend to do a grouping using the UI with a dummy aggregation and then replace it with the formula for the geometric mean:
Number.Power(List.Product([Duration]), 1 / List.Count([Duration]))
Please paste the following code into the advanced editor and follow the steps:let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "i45WCg1Q0lHy9wAS4ZlFqTmZealApqOjI0jU0wdIGuqZKsXqEKHQiFiFFlCFLv7hfkBuWDBIg0tRZk5OQWYBSLGTkxNId2JJahGSA4hUbkaacnNkV7uFBKM629nZGbv/8Ko0BamMBQA=", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ Direction = _t, #"Job Type" = _t, Conveyance = _t, #"Field Name" = _t, Base = _t, Duration = _t ] ), #"Changed Type" = Table.TransformColumnTypes( Source, { {"Direction", type text}, {"Job Type", type text}, {"Conveyance", type text}, {"Field Name", type text}, {"Base", type text}, {"Duration", type number} } ), #"Grouped Rows" = Table.Group( #"Changed Type", {"Direction", "Job Type", "Conveyance", "Field Name", "Base"}, { { "Geo Mean", each Number.Power(List.Product([Duration]), 1 / List.Count([Duration])), type nullable number }, {"Partition", each _} } ), #"Expanded Partition" = Table.ExpandTableColumn( #"Grouped Rows", "Partition", {"Duration"}, {"Duration"} ) in #"Expanded Partition"
ImkeF
3 years agoCommunity Champion
Hi Anonymous ,
I would recommend to do a grouping using the UI with a dummy aggregation and then replace it with the formula for the geometric mean:
Number.Power(List.Product([Duration]), 1 / List.Count([Duration]))
Please paste the following code into the advanced editor and follow the steps:
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WCg1Q0lHy9wAS4ZlFqTmZealApqOjI0jU0wdIGuqZKsXqEKHQiFiFFlCFLv7hfkBuWDBIg0tRZk5OQWYBSLGTkxNId2JJahGSA4hUbkaacnNkV7uFBKM629nZGbv/8Ko0BamMBQA=",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [
Direction = _t,
#"Job Type" = _t,
Conveyance = _t,
#"Field Name" = _t,
Base = _t,
Duration = _t
]
),
#"Changed Type" = Table.TransformColumnTypes(
Source,
{
{"Direction", type text},
{"Job Type", type text},
{"Conveyance", type text},
{"Field Name", type text},
{"Base", type text},
{"Duration", type number}
}
),
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"Direction", "Job Type", "Conveyance", "Field Name", "Base"},
{
{
"Geo Mean",
each Number.Power(List.Product([Duration]), 1 / List.Count([Duration])),
type nullable number
},
{"Partition", each _}
}
),
#"Expanded Partition" = Table.ExpandTableColumn(
#"Grouped Rows",
"Partition",
{"Duration"},
{"Duration"}
)
in
#"Expanded Partition"