Stop 02 · Connecting to DataProjects · 1/1

Combine a Folder of Monthly Sales Files

Part of the Power BI Roadmap

In short

Every month a new sales CSV lands in a folder. Instead of copy-pasting twelve files together, you build one query that swallows the whole folder and picks up next month's file on its own.

A project that combines twelve monthly sales CSVs from one folder into a single table, adds the source file name as a column, and proves that a new month appears after a refresh.

The jaadu stitches a stack of twelve thin magazines together into one thick bound volume with coloured tabs sticking out.

Think of it like this

Binding monthly magazines into one volume

A library binds twelve monthly issues of a magazine into one thick yearly volume, with a label on each section showing which month it came from. The Folder connector does the same: every file becomes a section of one big table, tagged with its file name.

Watch it happen

Twelve files become one table

Folder.Files
Keep CSVs
Parse each
Expand
Add month

1/5Folder.Files lists 13 items: twelve monthly CSVs and a stray notes.txt.

The big ideas

What you need to know

Same layout required

Every file must have the same columns in the same meaning. Check one odd file before blaming Power Query.

Keep the file name

The Name column records the source file, which is priceless when one month looks wrong.

Filter the junk

Filter by Extension and Name so temp files and notes never get combined.

Prove it with refresh

Drop next month's file into the folder, click Refresh and watch the row count grow.

See it in code

Walk through the code

m
1let2    Source = Folder.Files("D:\Sales\Monthly"),3    CsvOnly = Table.SelectRows(Source, each [Extension] = ".csv"),4    Parsed = Table.AddColumn(5        CsvOnly,6        "Data",7        each Table.PromoteHeaders(8            Csv.Document([Content], [Delimiter = ",", Encoding = 65001]),9            [PromoteAllScalars = true]10        )11    ),12    Slim = Table.SelectColumns(Parsed, {"Name", "Data"}),13    Expanded = Table.ExpandTableColumn(14        Slim, "Data", {"OrderID", "OrderDate", "City", "Amount"}15    ),16    Typed = Table.TransformColumnTypes(17        Expanded,18        {{"OrderID", Int64.Type}, {"OrderDate", type date},19         {"City", type text}, {"Amount", Currency.Type}},20        "en-IN"21    )22in23    Typed

1/4List all files in the folder and keep only CSVs.

A hand-written version of Combine Files: one query, every CSV in the folder, typed and tagged with its file name.

Save yourself the pain

Common mistakes

Oops

Combining before checking that every file has the same headers.

Do this instead

Open two or three files first. One file with a renamed column silently creates a column of nulls.

Oops

Removing the Name column right after combining.

Do this instead

Keep it at least while testing. It tells you exactly which file a bad row came from.

Your mission

Build the monthly pipeline

~45 min

Quick check

Next month's file arrives in the folder. What do you need to change in the query?

Go deeper

  1. 1Create or download twelve small monthly files with identical columns.
  2. 2Keep the file name column so you can trace each row back to its month.
  3. 3Drop a thirteenth file in the folder and refresh to test the setup.

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge