Forum Discussion

bartvana's avatar
bartvana
Iron Contributor
Sep 11, 2021
Solved

Percentiles from frequency table

Hello, This is a quite common problem to solve in statistics it seems to me, but I can't find an easy solution in Excel. Am I missing something or is this just something that's not incorporated? Th...
  • SergeiBaklan's avatar
    SergeiBaklan
    Sep 11, 2021

    bartvana 

    You may group by Product without aggregation and apply former procedure to each group

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Grouped Rows" = Table.Group(
            Source, {"Product"},
            {{"Percentile",
                    each
                    [
                        allValues = Table.AddColumn(
                        _ ,
                        "Lists",
                        each List.Numbers([Value],[Frequency],0)
                        ),
                        Percentile = List.Percentile (
                            List.Combine(allValues[Lists]), 0.5
                        )                
                    ][Percentile]
            }}
        )
    in
        #"Grouped Rows"

    or use function instead

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    
        fnPercentile = (tbl as table) => 
            let
                allValues = Table.AddColumn(
                    tbl , "Lists",
                        each List.Numbers([Value],[Frequency],0)
                ),
                Percentile = List.Percentile (
                    List.Combine(allValues[Lists]), 0.5
                )                
            in
                Percentile,
    
        #"Grouped Rows" = Table.Group(
            Source, {"Product"},
            {{ "Percentile", each fnPercentile(_) }}
        )
    in
        #"Grouped Rows"

    Here the only we assume predefined column names in functions.

     

    I'd filter Frequency = 0 before grouping.

    In attached file is above and "Excel variant".

Resources