
Percentile calculation by group

giovanni zanocco
Posts: 1


May 18, 2023 - 2:50 am
1
Hi all,
I am struggling with the following problem: I have a sample data set where I need to calculate the n percentile (say 90% percentile) for records pertaining to a given Area (see screenshot). The percentile of each Area should then be reported in an additional column.
Hope the screenshot clarifies the problem.
Thank you
giovanni

Catalin Bombea
Iasi, Romania
Posts: 1824

May 25, 2023 - 2:42 pm
2
Hi Giovanni,
Try this query:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Grouped", (x)=> List.Sum(Table.SelectRows(Source, each _[Area] = x[Area])[Custom.Peso])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Percent", each [Custom.Peso]/[Grouped], Percentage.Type)
in
#"Added Custom1"
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Grouped", (x)=> List.Sum(Table.SelectRows(Source, each _[Area] = x[Area])[Custom.Peso])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Percent", each [Custom.Peso]/[Grouped], Percentage.Type)
in
#"Added Custom1"
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 12
Currently Browsing this Page:
1 Guest(s)
1 Guest(s)
Devices in use: Desktop (9), Phone (3)
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793
Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4