Power Query Intermediate Lesson 8: Project – ERP Register to HSN-wise GST Summary

Power Query Intermediate Lesson 8: Project - ERP Register to HSN-wise GST Summary 1

📎 This article includes 3 downloadable practice files ↓

⏱ 2 min read

📘 Power Query Intermediate Course · Lesson 8 of 8

Advertisement

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

  1. Import erp-register.csv and set types (Rev whole number, Date, Taxable, GST Rate).
  2. Latest revision only: Group By Invoice with Table.Max(_, "Rev") (lesson 4), expand.
  3. Add GST = Number.Round([Taxable] * [GST Rate], 2).
  4. 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.

💡 Load the summary next to last month’s and add a difference column. A sudden jump in one HSN is usually a wrong code in the ERP, and much cheaper to fix before filing than after.
⚠️ This is a practice summary. Check the current GSTR-1 HSN reporting rules (digits required, B2B/B2C split) for your turnover before using it for a return.

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.

Advertisement
✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *