Cumulative total while grouping

ErsinALACA

New Member
Joined
Mar 6, 2020
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
Hi; While browsing the Internet, I encountered a file with the following codes. Creating an Index; during grouping. Can we improve this process? I tried, I couldn't. Can we get a cumulative total for Nb Items (line by line)?

Ekran Alıntısı.PNG


VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Supplier", type text}, {"Item", type text}, {"Nb Item", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Supplier", Order.Ascending}, {"Nb Item", Order.Descending}}),
    #"Group by Supplier" = Table.Group(#"Sorted Rows", {"Supplier"}, {{"Partition", each Table.AddIndexColumn(_, "Rank", 1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(#"Group by Supplier", "Partition", {"Item", "Nb Item", "Rank"}, {"Item", "Nb Item", "Rank"})
in
     #"Expanded Partition"

Thanks in advance.
 

Attachments

  • Ekran Alıntısı.PNG
    Ekran Alıntısı.PNG
    57.6 KB · Views: 5
  • 1583737856190.png
    1583737856190.png
    312 bytes · Views: 5

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Table1Rank_nbItems_per_Supplier
SupplierItemNb ItemSupplierItemNb ItemRank
TimCar12JohnComputer151
TimTv5JohnTv52
TimMobile phone22JohnMobile phone23
JohnCar1JohnCar14
JohnTv5MichaelMobile phone221
JohnMobile phone2MichaelCar152
JohnComputer15MichaelComputer73
MichaelCar15MichaelTv24
MichaelTv2TimMobile phone221
MichaelComputer7TimCar122
MichaelMobile phone22TimTv53


I was looking for this XL2BB :)
 
Upvote 0
here is step-by-step
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Supplier", type text}, {"Item", type text}, {"Nb Item", Int64.Type}}),
    Sort = Table.Sort(Type,{{"Supplier", Order.Ascending}, {"Nb Item", Order.Descending}}),
    Group = Table.Group(Sort, {"Supplier"}, {{"Count", each _, type table}}),
    Expand = Table.ExpandTableColumn(Group, "Count", {"Item", "Nb Item"}, {"Item", "Nb Item"}),
    Index0 = Table.AddIndexColumn(Expand, "Index", 0, 1),
    Mod = Table.TransformColumns(Index0, {{"Index", each Number.Mod(_, 4), type number}}),
    Add1 = Table.TransformColumns(Mod, {{"Index", each _ + 1, type number}})
in
    Add1
 
Upvote 0

Forum statistics

Threads
1,223,799
Messages
6,174,669
Members
452,576
Latest member
AlexG_UK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top