Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
QZ
Helper I
Helper I

(M code)How to extract multiple sheet data from Excel which in multiple folder by Power Query(noDAX)

The budget Excel file save in folder every month, the folder name named by year and month, for example: 202401, 202402, ......,
(refer bellow picture, for the purpose of simplification, only save the excel file in 202401 and 202405 folder)

In the Excel file, each department has each sheet, for example: HR, IT, ......, 

The budget amount be allocated by quarter, for example, Q1, Q2, Q3, Q4,

The budget be divided into category and sub category, for example: category: Fixed costs; sub category: variable costs, labor costs, fixed costs(except labor costs),

My purpose is extracting all sheets data in excels which under D:\DeptBudget folder by Power Query(not DAX), final get table data(pls refer bellow picture which in green rectangular frame), it would by much appreciated if anyone afford the accomplishing method.

* Refer bellow video: Combine Excel Worksheet Data , I can extract the raw data which under D:\DeptBudget folder excel files(just like get data from folder in Power BI Desktop), but that's not what I want. I can process the budget amount by catetory and sub category for individual department sheet, but have no idea to multiple department sheets.

QZ_0-1722234790199.png

 

 

5 REPLIES 5
QZ
Helper I
Helper I

is it possible to inside cell then directly update cell value?
refer bellow pic, cell value is a table, can change value from red rectangular frame to green rectangular frame directly by Power Query?

QZ_0-1722412279482.png

 

Anonymous
Not applicable

Hi @QZ ,
Based on your description, you can try to perform the following steps:
First, choose get data from folder

vheqmsft_0-1722305999430.png

Then,choose the target folder and open and choose the combine and transfrom data

vheqmsft_1-1722306080094.png

Click ok

vheqmsft_2-1722306138366.png

Open the advanced editor and paste the Mcode

 

let
    Source = Folder.Files("C:\Users\yourcomputername\Desktop\DeptBudget"),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content", "Name"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Excel.Workbook([Content])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Custom.Name", "Custom.Data", "Custom.Item", "Custom.Kind", "Custom.Hidden"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Expanded Custom",{"Custom.Name", "Custom.Data"}),
    #"Expanded Custom.Data" = Table.ExpandTableColumn(#"Removed Other Columns1", "Custom.Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6"}, {"Custom.Data.Column1", "Custom.Data.Column2", "Custom.Data.Column3", "Custom.Data.Column4", "Custom.Data.Column5", "Custom.Data.Column6"})
in
    #"Expanded Custom.Data"

 

Final output

vheqmsft_3-1722306295183.png

Note that you can format all the data before merging it, so that you can get the data into the desired format faster.
How to Merge [Combine] Multiple Excel FILES into ONE WORKBOOK (excelchamps.com)

 

Best regards,
Albert He

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

 

 

thank for your reply!

the table format of your final output is not what I want, my purpose is get bellow format table:

QZ_0-1722307461279.png

QZ
Helper I
Helper I

I think if use method of getting data from folder, it's hard to process the raw data as request, is it?

QZ
Helper I
Helper I

You can get the original excel sample by click here: DeptBudget

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors