
π This article includes 3 downloadable practice files β
In this article
ERP exports often contain revised invoices: the same invoice number with Rev 1 and Rev 2. Summing everything double-counts them. This project produces a clean HSN summary from such a register.
Steps
- Import
erp-register.csvand set types (Rev whole number, Date, Taxable, GST Rate). - Latest revision only: Group By Invoice with
Table.Max(_, "Rev")(lesson 4), expand. - Add
GST = Number.Round([Taxable] * [GST Rate], 2). - Group By HSN and GST Rate: count of invoices, sum of Taxable, sum of GST.
Latest = Table.Group(Source, {"Invoice"}, {{"Row", each Table.Max(_, "Rev"), type record}}),
Rows = Table.ExpandRecordColumn(Latest, "Row", {"Rev", "Date", "HSN", "Taxable", "GST Rate"}),
Tax = Table.AddColumn(Rows, "GST", each Number.Round([Taxable] * [GST Rate], 2), type number),
Summary = Table.Group(Tax, {"HSN", "GST Rate"},
{{"Invoices", each Table.RowCount(_), Int64.Type},
{"Taxable", each List.Sum([Taxable]), type number},
{"GST", each List.Sum([GST]), type number}})
The register has 30 rows but only 25 invoices; the summary correctly counts 25.
Practice
Unzip the source files (e.g. to D:\PQ\). Try to build the query with the ribbon first, then compare with the M solution and the expected result. Every solution was run by Excel’s own Power Query engine before publishing.
π Practice files for this article
β¬ Download all 3 files (ZIP Β· 8 KB)
- ποΈPractice source files (zip)All messy CSVs for the course: invoices, payments, typed customer names, credit history, contacts, branch files, a two-row-header report and an ERP register.β¬ ZIP Β· 3 KB
- πLesson 8 M solutionThe full query. Paste into Advanced Editor and change the Folder line.β¬ PQ Β· 1 KB
- πExpected resultWhat the query returned when Excel ran it, to compare with yours.β¬ XLSX Β· 5 KB
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.