Data Cost Coding

Silvo

New Member
Joined
May 10, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I'm trying to analyse some costs produced in some 3rd party software. The costs have a structure/hierarchy but I want to manipulate it with a Power Query to get it into a format that I can run Pivot Tables and similar analysis from.

Basically, each item is assigned a level. The level is linked to the next item above it with a lower level. So an item with level 4 would also be linked to the next items 3, 2, 1 and 0 on the rows above. The costs can then be looked at from a high level or a low level. The number of levels is not fixed and could go several levels deep but generally it is only 3-4 and varies within each project.

I feel like the best solution is to give each line a code but I keep running into issues and I'm sure there must be a clean way to do what I'm after but I've been trying for a few weeks on and off and I'm stuck. I have got it working in Excel using formula but I'd really prefer to get it working with a query and was hoping someone could point me in the right direction.

(Code and End result examples below)

Thanks for reading.

LevelDescriptionGross Total
0Group
1Heading 1
2Heading 2
3ItemNIL
3ItemNIL
3Item101,622
3Item0
3Item61,513
3Item0
3Item0
3Item50,018
3Item22,042
3Item0
3Item0
3Item0
3Item0
3Item24,427
3Item21,181
3Item0
3Item35,012
3Item0
3Item0
3Item0
3Item13,560
3ItemNIL
3ItemNIL
3ItemNIL
2Heading 2
3Item9,945
3Item0
3Item7,373
3Item0
3Item0
3Item6,597
3Item2,907
3Item0
3ItemINC
3Item0
3Item0
3Item9,945
3Item9,945
3Item0
3Item4,499
3Item0
3ItemINC
3Item0
3Item4,902
3ItemNIL
3ItemNIL
3ItemNIL
2Heading 2
3Item1,080
2Heading 2
2ItemEXC
2Item0
2Item0
2Heading 2
3ItemEXC
1Heading 1
2Heading 2
3Item3,150
3Item900
3Item0
3Item0
3Item0
3Item0
3Item0
3Item0
3Item0
3Item0
3Item0
3Item0
3Item24,700
3Item390
3Item3,055
3Item3,484
3Item2,400
3Item1,440
3Item2,400
3Item1,080
3Item5,920
3Item2,125
3Item2,520
3Item430
3Item1,800
3Item0
3ItemNIL
3ItemNIL
3Item500
3Item0
3Item350
3Item892
3Item0
3Item0
3Item850
2Heading 2
3Item1,500
3Item1,500
3Item700
3Item6,500
3Item1,500
3Item1,500
3Item140
3Item1,440
3Item0
3Item7,000
3Item500
3Item500
3Item0
3Item1,800
3Item98
3Item8,280
2Heading 2
3Item8,064
3Item12,600
3Item0
3Item0
3Item3,280
3Item0
3Item0
3Item21,641
3Item1,355
3Item0
3Item1,270
3Item850
3Item0
3Item16,532
3Item0
2Heading 2
3Item2,000
3Item2,500
3Item2,500
2Heading 2
3Item0
3Item4,234
3Item6,554
3Item18,270
3Item2,842
3Item2,030
3Item1,983
3Item0
3Item0
3Item18,293
3Item27,000
3Item3,033
2Heading 2
3Item0
3Item3,600
2Heading 2
3Item720
3Item2,880
2Heading 2
3ItemNIL
2Heading 2
3Item200
3Item3,600
1Heading 1
2Heading 2
3ItemNIL
3ItemNIL
1Heading 1
2Heading 2
3Item44,250
3Item16,500
3Item40,300
3Item24,800
3Item0
3Item0
3Item0
3Item0
3Item44,640
3Item0
1Heading 1
2Heading 2
3Item9,971
3Item3,718
3Item0
2Heading 2
3Item0
3Item0
3Item0
3Item0
3Item0
3Item1,500
3Item29,040
3ItemEXC
3ItemEXC
3Item1,110
3Item72
3Item0
3Item0
2Heading 2
3ItemNIL
3ItemNIL
2Heading 2
3ItemNIL
2Heading 2
3Item19,588
3Item7,304
3Item0
3Item0
2Heading 2
3Item20,625
3Item0
2Heading 2
3Item0
2Heading 2
3Item52,500
3Item1,944
1Heading 1
2Heading 2
3ItemNIL
3ItemNIL
2Heading 2
3ItemNIL
3ItemNIL
3ItemNIL
2Heading 2
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
2Heading 2
3ItemNIL
3ItemNIL
2Heading 2
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL
1Heading 1
2Heading 2
3Item4,097
3Item0
3Item14,400
3Item0
2Heading 2
3Item0
3Item0
3Item6,750
3Item7,200
3Item14,000
3Item12,240
3Item10,000
3Item6,000
3Item0
3Item0
3Item1,500
3Item4,551
3Item1,638
2Heading 2
3ItemNIL
1Heading 1
2Heading 2
3ItemNIL
3ItemNIL
3ItemNIL
2Heading 2
3ItemNIL
3ItemNIL
3ItemNIL
3ItemNIL


This is the code I came up with using a formula but I'd really like to understand how I can do something like this in PQ. The formula I used was using Countifs and I feel I got close with Index and List.Sum and List.FirstN in PQ:

LevelCode3
000_00_00
101_00_00
201_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
301_01_00
201_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
301_02_00
201_03_00
301_03_00
201_04_00
201_04_00
201_04_00
201_04_00
201_05_00
301_05_00
102_00_00
202_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
302_01_00
202_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
302_02_00
202_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
302_03_00
202_04_00
302_04_00
302_04_00
302_04_00
202_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
302_05_00
202_06_00
302_06_00
302_06_00
202_07_00
302_07_00
302_07_00
202_08_00
302_08_00
202_09_00
302_09_00
302_09_00
103_00_00
203_01_00
303_01_00
303_01_00
104_00_00
204_01_00
304_01_00
304_01_00
304_01_00
304_01_00
304_01_00
304_01_00
304_01_00
304_01_00
304_01_00
304_01_00
105_00_00
205_01_00
305_01_00
305_01_00
305_01_00
205_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
305_02_00
205_03_00
305_03_00
305_03_00
205_04_00
305_04_00
205_05_00
305_05_00
305_05_00
305_05_00
305_05_00
205_06_00
305_06_00
305_06_00
205_07_00
305_07_00
205_08_00
305_08_00
305_08_00
106_00_00
206_01_00
306_01_00
306_01_00
206_02_00
306_02_00
306_02_00
306_02_00
206_03_00
306_03_00
306_03_00
306_03_00
306_03_00
306_03_00
306_03_00
306_03_00
306_03_00
306_03_00
206_04_00
306_04_00
306_04_00
206_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
306_05_00
107_00_00
207_01_00
307_01_00
307_01_00
307_01_00
307_01_00
207_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
307_02_00
207_03_00
307_03_00
108_00_00
208_01_00
308_01_00
308_01_00
308_01_00
208_02_00
308_02_00
308_02_00
308_02_00
308_02_00


And this is the final result of what I'm trying to do:

Row LabelsSum of Gross Total
01
00
01386,568
02259,175
030
04170,490
05147,372
060
0782,376
080
01 Total1,045,981
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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