Forum Discussion

AllanBerces's avatar
AllanBerces
Post Prodigy
11 months ago
Solved

Total and Rank

Hi good day can anyone help me on my PQ, what we required is the Total sum of trade and Rank it from Highest to Lowest. if the Rank 1 is two date let say 5/14 and 5/13 used the latet date.   ...
  • AlienSx's avatar
    AlienSx
    11 months ago

    hello, AllanBerces . Create new (blank) query and replace everything inside with this code:

    let
        // your code 
        Source = #"Complete_List Actual POB",
        your_group = Table.Group(
            Source, 
            {"DPR_DATE", "Combine Direct and InDirect", "BP's"}, 
            {{"Sum Trade", each Table.RowCount(_), Int64.Type}}
        ),
        // my code
        my_group = Table.Group(
            your_group, 
            "DPR_DATE", 
            {
                {"tbl", (x) => x}, 
                {"Total Trade", (x) => List.Sum(x[Sum Trade])}
            }
        ),
        rank = Table.AddRankColumn(
            my_group, 
            "Rank",
            {{"Total Trade", Order.Descending}, {"DPR_DATE", Order.Descending}}, 
            [RankKind = RankKind.Ordinal]
        ),
        xpand = Table.ExpandTableColumn(rank, "tbl", List.RemoveItems(Table.ColumnNames(your_group), {"DPR_DATE"}))
    in
        xpand