I am using Office 2019 and i want to add a summation row after every last unique ref "GRV" and also the cell below the last unique reference "GRV', i want to sum totals of Columns "Tpt Charge","Offloading Fee" & "Tollgate Fee". How do i do that?
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
Custom1 = Table.Combine(Table.Group(Source,"GRV",{"n",each let c=Table.ToColumns(_) in #table(Table.ColumnNames(_),Table.ToRows(_)&{{null,null,null,null}&Record.ToList([m=List.Sum(c{4}),n=List.Sum(c{5}),o=List.Sum(c{6}),p=List.Sum(c{7}),q=m+n+o+p,r=null])})})[n])
in
Custom1
供参考.xlsx | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | |||
1 | Despath Date | Site | SBU | Order Number | Tonnes | Tpt Charge | Offloading Fee | Tollgate Fee | GRV | p/order | ||
2 | 45 | 38 | 74 | 5 | Q1 | 16759 | ||||||
3 | 94 | 8 | 76 | 72 | Q1 | 16759 | ||||||
4 | 84 | 35 | 54 | 62 | Q1 | 16759 | ||||||
5 | 79 | 32 | 42 | 78 | Q2 | 16759 | ||||||
6 | 99 | 33 | 43 | 98 | Q2 | 16760 | ||||||
7 | 86 | 60 | 27 | 49 | Q2 | 16760 | ||||||
8 | 40 | 12 | 49 | 78 | Q2 | 16760 | ||||||
9 | 62 | 34 | 30 | 2 | Q2 | 16763 | ||||||
10 | 93 | 75 | 33 | 69 | Q3 | 16763 | ||||||
11 | 50 | 39 | 27 | 37 | Q3 | 16763 | ||||||
12 | Despath Date | Site | SBU | Order Number | Tonnes | Tpt Charge | Offloading Fee | Tollgate Fee | GRV | p/order | ||
13 | 45 | 38 | 74 | 5 | Q1 | 16759 | ||||||
14 | 94 | 8 | 76 | 72 | Q1 | 16759 | ||||||
15 | 84 | 35 | 54 | 62 | Q1 | 16759 | ||||||
16 | 223 | 81 | 204 | 139 | 647 | |||||||
17 | 79 | 32 | 42 | 78 | Q2 | 16759 | ||||||
18 | 99 | 33 | 43 | 98 | Q2 | 16760 | ||||||
19 | 86 | 60 | 27 | 49 | Q2 | 16760 | ||||||
20 | 40 | 12 | 49 | 78 | Q2 | 16760 | ||||||
21 | 62 | 34 | 30 | 2 | Q2 | 16763 | ||||||
22 | 366 | 171 | 191 | 305 | 1033 | |||||||
23 | 93 | 75 | 33 | 69 | Q3 | 16763 | ||||||
24 | 50 | 39 | 27 | 37 | Q3 | 16763 | ||||||
25 | 143 | 114 | 60 | 106 | 423 | |||||||
Sheet2 |
Yes, for beginners it is not easy to understand and apply. GUI+M function would be a better way.Rather advanced with the let inside a function and the compressed code for grouping. Impressive. Not sure if less advanced user can adopt this easily.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Grouped = Table.Combine(Table.Group(Source,"GRV",{"C",each let a={List.Sum([Tonnes]),List.Sum([Tpt Charge]),List.Sum([Offloading Fee]),List.Sum([Tollgate Fee])} in Table.Combine({_,#table( List.Range(Table.ColumnNames(_),4,5),{a&{List.Sum(a)}})})})[C])
in
Grouped