Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
AllanBerces
Post Prodigy
Post Prodigy

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.

 

AllanBerces_0-1757073038219.png

RESULT

AllanBerces_1-1757073086678.png

DATEDirect and InDirectComSum TradeTotal TradeRank
5/14/2025E&I ArtisanE&I81131
5/14/2025BanksmanScaff421131
5/14/2025Marker Mech631131
5/9/2025E&I ArtisanE&I7782
5/9/2025BanksmanScaff33782
5/9/2025Marker Mech38782
6/12/2025E&I ArtisanE&I3743
6/12/2025BanksmanScaff48743
6/12/2025Marker Mech23743
5/7/2025E&I ArtisanE&I7714
5/7/2025BanksmanScaff36714
5/7/2025Marker Mech28714
5/8/2025E&I ArtisanE&I4685
5/8/2025BanksmanScaff34685
5/8/2025Marker Mech30685
5/6/2025E&I ArtisanE&I6566
5/6/2025BanksmanScaff37566
5/6/2025Marker Mech13566
1 ACCEPTED SOLUTION

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

View solution in original post

4 REPLIES 4
AlienSx
Super User
Super User

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    group = Table.Group(
        Source, 
        "DATE", 
        {
            {"tbl", (x) => x}, 
            {"Total trade", (x) => List.Sum(x[Sum Trade])}
        }
    ),
    rank = Table.AddRankColumn(
        group, 
        "Rank",
        {{"Total trade", Order.Descending}, {"DATE", Order.Descending}}, 
        [RankKind = RankKind.Ordinal]
    ),
    xpand = Table.ExpandTableColumn(rank, "tbl", List.RemoveItems(Table.ColumnNames(Source), {"DATE"}))
in
    xpand

Hi @AlienSx thank you very much how can i add that to my current query

 

let
Source = #"Complete_List Actual POB",
#"Grouped Rows" = Table.Group(Source, {"DPR_DATE", "Combine Direct and InDirect", "BP's"}, {{"Sum Trade", each Table.RowCount(_), Int64.Type}})
in
#"Grouped Rows"

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

Hi @AlienSx thank you very much for the reply working perfectly

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors