Excel PowerQuery with subtotal required to replace old VBA code that is too slow

PeterMac65

New Member
Joined
May 7, 2020
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi,
In the recent past i was using VBA to step through approx 2000 rows and if the "Total" column was not ZERO i would copy to a new sheet the following columns:
OrderCode (used to perform a future sort)
Product Name
Quantity
Price
Unit of Measure
Total

I then sorted the data by OrderCode

And added a subtotal for each OrderCode.

What used to take < 30 seconds now takes up to 5 minutes.

I think I could achieve this using a Power Query instead. Could someone please point me in the right direction with particular focus in how to include a subtotal

Regards Peter
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Load some sample data and a mocked up solution using XL2BB. Do not post a picture as we cannot manipulate data in a picture.
 
Upvote 0
Hi Alan, I've loaded some sample data

Book3
ABCDEFGHIJKLMN
1Job subcodeOrder-RefCodeDescription 1SubtotalQuantitySuggestUnitsPriceTotalColumn1ExcludeProductTitle
23P&G, on site costs & Insurance$31,369.08
31007Additional Design Time & QS Time1Sum$680.00$680.00Provision - No Order
4$0.00Provision - No Order
5Provision - No Order
6100661Not included by owner's request11$0.00$0.00Exclude10 year Master Builders standard guarantee includedProvision - No Order
7Provision - No Order
83.01Master Builder 10 Year Standard Guarantee $ 479,165.43Provision - No Order
9100661Over $200,000 to $400,00000each$1,130.43$0.00Masterbuild Over $200,000 to $400,000Provision - No Order
10100661Over $400,000 to $600,00011each$1,304.35$1,304.35Masterbuild Over $400,000 to $600,000Provision - No Order
11100661Over $600,000 to $800,00000each$1,521.74$0.00Masterbuild Over $600,000 to $800,000Provision - No Order
12100661Over $800,000 to $1,000,00000each$1,695.65$0.00Masterbuild Over $800,000 to $1,000,000Provision - No Order
13100661Over $1,000,000 to $1,500,00000each$1,913.04$0.00Masterbuild Over $1,000,000 to $1,500,000Provision - No Order
14100661Over $1,500,000 to $2,000,00000each$2,391.30$0.00Masterbuild Over $1,500,000 to $2,000,000Provision - No Order
15100661$2,000,000+ Call us00each$2,826.09$0.00Masterbuild Over $2,000,000Provision - No Order
16Provision - No Order
17100662Insurance by owner11note$0.00$0.00ExcludeBuilders risk insurance includedProvision - No Order
181006623.02Construction Work Insurance179179m2$7.50$1,342.50Construction Work InsuranceProvision - No Order
19Provision - No Order
20Architect Provision - No Order
21100751Concept / sales plan01sum$750.00$0.00Concept / sales planProvision - No Order
22100752Building consent submission 11sum$750.00$750.00Building consent submission Provision - No Order
23100752Design (draft) - 1 storey179179m2$15.00$2,685.00Design (draft) - 1 storeyProvision - No Order
24Provision - No Order
253.04Temporary ServicesProvision - No Order
261008170Temporary Power11each$890.00$890.00Temporary PowerTemporary Power
271008260Three Phase Utility mains up to 20 metres11each$1,300.00$1,300.00Three Phase Utility mains up to 20 metresServices (Power, Water, Data)
281008260Power & Water 1818week$40.00$720.00Power & Water Services (Power, Water, Data)
291008999Temporary erosion & sediment control as an extra if required during construction11sum$0.00$0.00Temporary erosion & sediment control as an extra if required during constructionProvision - No Order
30Provision - No Order
311008Plant and small tools00week$0.00$0.00Plant and small toolsProvision - No Order
32Provision - No Order
333.05Scaffolding & NetsProvision - No Order
341015340Scaffolding supplied and installed by owner as required11note$0.00$0.00ExcludeAs required, supplied and installed by XXXScaffolding
351015340Scaffolding - provisional sum11pcsum$0.00$0.00ExcludeAs required, supplied and installed by XXXScaffolding
361015340Erection/dismatle/cartage $45 x lm6666sum$45.00$2,970.00Scaffold Erection/dismatle/cartageScaffolding
371015340Weekly rental $2.4 x lm 55week$158.40$792.00Scaffold Weekly rentalScaffolding
381015340Weekly rental Gable $7.2 x lm33week$57.60$172.80Scaffold Weekly rental GableScaffolding
391015340Weekly Inspection (depends on lm_gable)88week$65.00$520.00Scaffold Weekly InspectionScaffolding
40Provision - No Order
411015350Safety nets supplied and installed by owner as required11note$0.00$0.00ExcludeAs required, supplied and installed by XXXSafety Nets
421014350Supply and installation of nets 179179m2$4.00$716.00Scaffold Nets Safety Nets
43Provision - No Order
443.06Site Sheds and SetupProvision - No Order
451017Container 1818week$0.00$0.00Container Provision - No Order
46PortalooProvision - No Order
471017180Portaloo Delivery & Collection , hire and cleaning service (incl. consumables)1818week$44.00$792.00PortalooSite Port a Loo (Temporary Toilet)
48Portaloo - alternativeProvision - No Order
491017180Portaloo weekly hire00week$12.00$0.00Nova Portaloo weekly hireSite Port a Loo (Temporary Toilet)
501017180Cleaning service (please provide fortnightly service)00fortnight$30.00$0.00Nova Portaloo cleaning servicesSite Port a Loo (Temporary Toilet)
511017180Portaloo delivery & collection00sum$50.00$0.00Nova Portaloo delivery and collectionSite Port a Loo (Temporary Toilet)
521016160Temporary fences @ $0.56 per week per lm1818weeks$11.20$201.60Temporary FencesTemporary Fencing
531016160Temporary Fence delivery11$50.00$50.00Temporary Fence deliveryTemporary Fencing
54Provision - No Order
553.07Waste ManagementProvision - No Order
5610202909m³ Bin Delivered to site (to be charged by weight) - Initial delivery Location of Skip TBC by builder on site11bins$380.00$380.00Clean up - BinsWaste Management (Rubbish Skip)
5710209999m³ Bin Delivered to site (to be charged by weight) -Additional delivery23bins$380.00$760.00Clean up - BinsProvision - No Order
581020999Clean up - Labour ($2 x Selling area)179179sum$2.00$358.00Clean up - LabourProvision - No Order
59Provision - No Order
6010219803.08Final Clean 179179m2$3.00$537.00Final Clean Final Clean
61Provision - No Order
623.09Others: Street Crossing, colour consultancy and XXX MeshProvision - No Order
631005Cutdown and base up only00sum$800.00$0.00Cutdown and base up onlyProvision - No Order
641033110Colour consultancy11sum$300.00$300.00Colour consultancyColour Consultant
651017160Temporary front fence supplied and installed by owner as required11note$0.00$0.00ExcludeAs required, supplied and installed by XXXTemporary Fencing
661017340Scaffolding - provisional sum11pcsum$0.00$0.00ExcludeAs required, supplied and installed by XXXScaffolding
671017999XXX Fence mesh11sum$300.00$300.00XXX Fence meshProvision - No Order
Sheet3


The result should look as below but with subtotals for each order-Ref

Book3
ABCDEFG
1Order-RefTitleDescription 1QuantityUnitsPriceTotal
352Provision - No OrderBuilding consent submission 1sum$750.00$750.00
1052Provision - No OrderDesign (draft) - 1 storey179m2$15.00$2,685.00
1861Provision - No OrderOver $400,000 to $600,0001each$1,304.35$1,304.35
2262Provision - No OrderConstruction Work Insurance179m2$7.50$1,342.50
23110Colour ConsultantColour consultancy1sum$300.00$300.00
26160Temporary FencingTemporary fences @ $0.56 per week per lm18weeks$11.20$201.60
27160Temporary FencingTemporary Fence delivery1$50.00$50.00
28170Temporary PowerTemporary Power1each$890.00$890.00
36180Site Port a Loo (Temporary Toilet)Portaloo Delivery & Collection , hire and cleaning service (incl. consumables)18week$44.00$792.00
37260Services (Power, Water, Data)Three Phase Utility mains up to 20 metres1each$1,300.00$1,300.00
38260Services (Power, Water, Data)Power & Water 18week$40.00$720.00
39290Waste Management (Rubbish Skip)9m³ Bin Delivered to site (to be charged by weight) - Initial delivery Location of Skip TBC by builder on site1bins$380.00$380.00
42340ScaffoldingErection/dismatle/cartage $45 x lm66sum$45.00$2,970.00
47340ScaffoldingWeekly rental $2.4 x lm 5week$158.40$792.00
52340ScaffoldingWeekly rental Gable $7.2 x lm3week$57.60$172.80
53340ScaffoldingWeekly Inspection (depends on lm_gable)8week$65.00$520.00
56350Safety NetsSupply and installation of nets 179m2$4.00$716.00
57980Final CleanFinal Clean 179m2$3.00$537.00
58999Provision - No Order9m³ Bin Delivered to site (to be charged by weight) -Additional delivery2bins$380.00$760.00
60999Provision - No OrderClean up - Labour ($2 x Selling area)179sum$2.00$358.00
64999Provision - No OrderXXX Fence mesh1sum$300.00$300.00
67Provision - No OrderAdditional Design Time & QS Time1Sum$680.00$680.00
Sheet3 (2)


Regards Peter
 
Upvote 0

Forum statistics

Threads
1,223,406
Messages
6,171,927
Members
452,434
Latest member
NUC_N_FUTS2

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