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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Saad_Hanif456
Helper I
Helper I

Combine Inconsistent Excel File - Each File Consist three Sheets

Dear Experts,

 

I need to combine the Excel files from the folder through power query on the following condition

1. Each files have three sheets and each file has a difference column sequence

2. The data below column headers should populated in the same column header where it exists in the excel sheet.

3.  Column Headers of Jan Excel File is

 

Jan - Column Headers (One Excel File three Sheets)
S.NoISB DSPRB DSSRB DS
1S.No.S.No.S.No.
2Employee IndexEmployee IndexEmployee Index
3Employee IdEmployee IdEmployee Id
4Employee NoEmployee NoEmployee No
5Employee NameEmployee NameEmployee Name
6DesignationDesignationDesignation
7DOJDOJDOJ
8DOLDOLDOL
9UnitUnitUnit
10DepartmentDepartmentDepartment
11Sub DepartmentSub DepartmentSub Department
12Client BranchClient BranchClient Branch
13DivisionDivisionDivision
14RegionRegionRegion
15CityCityCity
16ProvinceProvinceProvince
17TerritoryTerritoryTerritory
18LocationLocationLocation
19RemarksRemarksRemarks
20Salary Per MonthSalary Per MonthSalary Per Month
21Current SalaryCurrent SalaryCurrent Salary
22MEAL ALLOWMEAL ALLOWMEAL ALLOW
23Add / DelAdd / DelAdd / Del
24OT HoursOT HoursOT Hours
25OT RateOT RateOT Rate
26OT AmountOT AmountOT Amount
27Travel AllowanceTravel Exp.Travel Exp.
28Travel Exp.Sp.OT AmountSp.OT Amount
29Sp.OT AmountWorking DaysWorking Days
30Working DaysExtra DaysExtra Days
31Extra DaysExtra Days AmountExtra Days Amount
32Extra Days AmountEx-GratiaEx-Gratia
33Ex-GratiaOther ArrearsOther Arrears
34Other ArrearsHardship AllowanceHardship Allowance
35Hardship AllowanceVeh Rep/MaintVeh Rep/Maint
36Other ExpTravel AllowanceTravel Allowance
37Absent DaysLaonAdjLaonAdj
38Absent Days AmountOther ExpOther Exp
39EOBIAbsent DaysAbsent Days
40EOBI Employer ArrearsAbsent Days AmountAbsent Days Amount
41Edu. CESSNotice SalaryNotice Salary
42ESSIEOBIEOBI
43Life Ins.EOBI Employer ArrearsEOBI Employer Arrears
44Health InsuranceEdu. CESSEdu. CESS
453rd Party Liab.ESSIESSI
46Bank ChargesLife Ins.Life Ins.
47Mobile AllowanceHealth InsuranceHealth Insurance
48Misc.3rd Party Liab.3rd Party Liab.
49LaonAdjBank ChargesBank Charges
50Gross TotalMobile AllowanceMobile Allowance
51Service ChargesMisc.Misc.
52General Sales TaxGross TotalGross Total
53Billing AmountService ChargesService Charges
54Refund To ClientGeneral Sales TaxGeneral Sales Tax
55I.TaxBilling AmountBilling Amount
56Professional TaxI.TaxI.Tax
57EOBI Emp ConLoan Ded.Loan Ded.
58Net SalaryProfessional TaxProfessional Tax
59 EOBI Emp ConEOBI Emp Con
60 EOBI Employee ArrearsEOBI Employee Arrears
61 Net SalaryNet Salary

 

5. Column Headers for Feb Excel File is

Feb - Column Headers (One Excel File three Sheets)
S.NoISB DSPRB DSSRB DS
1S.No.S.No.S.No.
2Employee IndexEmployee IndexEmployee Index
3Employee IdEmployee IdEmployee Id
4Employee NoEmployee NoEmployee No
5Employee NameEmployee NameEmployee Name
6DesignationDesignationDesignation
7DOJDOJDOJ
8DOLDOLDOL
9UnitUnitUnit
10DepartmentDepartmentDepartment
11Sub DepartmentSub DepartmentSub Department
12Client BranchClient BranchClient Branch
13DivisionDivisionDivision
14RegionRegionRegion
15CityCityCity
16ProvinceProvinceProvince
17TerritoryTerritoryTerritory
18LocationLocationLocation
19RemarksRemarksRemarks
20Salary Per MonthSalary Per MonthSalary Per Month
21Current SalaryCurrent SalaryCurrent Salary
22MEAL ALLOWMEAL ALLOWMEAL ALLOW
23Add / DelAdd / DelAdd / Del
24OT HoursOT HoursOT Hours
25OT RateOT RateOT Rate
26OT AmountOT AmountOT Amount
27Travel AllowanceTravel Exp.Travel Exp.
28Travel Exp.Sp.OT AmountSp.OT Amount
29Sp.OT AmountWorking DaysWorking Days
30Working DaysExtra DaysExtra Days
31Extra DaysExtra Days AmountExtra Days Amount
32Extra Days AmountEx-GratiaEx-Gratia
33Ex-GratiaOther ArrearsOther Arrears
34Other ArrearsHardship AllowanceHardship Allowance
35Hardship AllowanceVeh Rep/MaintVeh Rep/Maint
36Other ExpTravel AllowanceTravel Allowance
37Absent DaysLaonAdjLaonAdj
38Absent Days AmountOther ExpOther Exp
39EOBIAbsent DaysAbsent Days
40EOBI Employer ArrearsAbsent Days AmountAbsent Days Amount
41Edu. CESSNotice SalaryNotice Salary
42ESSIEOBIEOBI
43ESSI ArrearsEOBI Employer ArrearsEOBI Employer Arrears
44Life Ins.Edu. CESSEdu. CESS
45Health InsuranceESSIESSI
463rd Party Liab.ESSI ArrearsESSI Arrears
47Bank ChargesLife Ins.Life Ins.
48Mobile AllowanceHealth InsuranceHealth Insurance
49Misc.3rd Party Liab.3rd Party Liab.
50LaonAdjBank ChargesBank Charges
51Gross TotalMobile AllowanceMobile Allowance
52Service ChargesMisc.Misc.
53General Sales TaxGross TotalGross Total
54Billing AmountService ChargesService Charges
55Refund To ClientGeneral Sales TaxGeneral Sales Tax
56I.TaxBilling AmountBilling Amount
57Professional TaxI.TaxI.Tax
58EOBI Emp ConLoan Ded.Loan Ded.
59Net SalaryProfessional TaxProfessional Tax
60EOBI Employee ArrearsEOBI Emp ConEOBI Emp Con
61 EOBI Employee ArrearsEOBI Employee Arrears
62 Net SalaryNet Salary

 

6. Desired columns headers are of Feb Month (PRB DS)

7. Column Header should be dynamic, if any new columns gets added in the month of March it automatically displayed accordingly.

8. Link of Files are (https://drive.google.com/drive/folders/16lMbD6T_DsyXE3UzYGWVuf_EwxLcRzDa?usp=sharing)

Please suggest the query in power bi so that i am able to perform the task asap

Regards,

Saad Hanif

 

5 REPLIES 5
PwerQueryKees
Impactful Individual
Impactful Individual

EDIT: I moved the data taken from the top rows of each sheet to beginning ow the table.

 

I love it when people actually include useable and downloadable data!

So I took it and here is my result (more columns to the right, but you get the picture)

PwerQueryKees_0-1732285450967.png

 

All done in one query, just create a blank query and paste and adapt...

 

let
    Source = Folder.Files("C:\Users\... your path to the folder containing your excel files here ..."),
    #"Keep Content and Name Columns" = Table.SelectColumns(Source,{"Content", "Name"}),
    #"Added Excel WorkBook as Column" = Table.AddColumn(#"Keep Content and Name Columns", "Excel", each Excel.Workbook([Content])),
    #"Expanded Excel Workbook" = Table.ExpandTableColumn(#"Added Excel WorkBook as Column", "Excel", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Excel.Name", "Excel.Data", "Excel.Item", "Excel.Kind", "Excel.Hidden"}),
    #"Filtered Work Sheets only" = Table.SelectRows(#"Expanded Excel Workbook", each [Excel.Kind] = "Sheet"),
    #"Removed Name and Data Columns" = Table.SelectColumns(#"Filtered Work Sheets only",{"Name", "Excel.Name", "Excel.Data"}),
    #"Added Header Info as List" = Table.AddColumn(#"Removed Name and Data Columns", "Header", each List.Range([Excel.Data][Column1],1,6)),
    #"Moved Header to Front" = Table.ReorderColumns(#"Added Header Info as List",{"Name", "Excel.Name", "Header", "Excel.Data"}),
    #"Convert Header Info to Text" = Table.TransformColumns(#"Moved Header to Front", {"Header", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Turn Header Info into Columns" = Table.SplitColumn(#"Convert Header Info to Text", "Header", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Header.1", "Header.2", "Header.3", "Header.4"}),
    #"Remove Header Rows and Promote Headers" = Table.TransformColumns(#"Turn Header Info into Columns",{{"Excel.Data", each Table.PromoteHeaders(Table.Skip(_,8), [PromoteAllScalars=true])}}),
    #"Expanded Excel.Data" = Table.ExpandTableColumn(#"Remove Header Rows and Promote Headers", "Excel.Data", {"S.No.", "Employee Index", "Employee Id", "Employee No", "Employee Name", "Designation", "DOJ", "DOL", "Unit", "Department", "Sub Department", "Client Branch", "Division", "Region", "City", "Province", "Territory", "Location", "Remarks", "Salary Per Month", "Current Salary", "MEAL ALLOW", "Add / Del", "OT Hours", "OT Rate", "OT Amount", "Travel Allowance", "Travel Exp.", "Sp.OT Amount", "Working Days", "Extra Days", "Extra Days Amount", "Ex-Gratia", "Other Arrears", "Hardship Allowance", "Other Exp", "Absent Days", "Absent Days Amount", "EOBI", "EOBI Employer Arrears", "Edu. CESS", "ESSI", "ESSI Arrears", "Life Ins.", "Health Insurance", "3rd Party Liab.", "Bank Charges", "Mobile Allowance", "Misc.", "LaonAdj", "Gross Total", "Service Charges", "General Sales Tax", "Billing Amount", "Refund To Client", "I.Tax", "Professional Tax", "EOBI Emp Con", "Net Salary", "EOBI Employee Arrears", "Veh Rep/Maint", "Notice Salary", "Loan Ded."}, {"S.No.", "Employee Index", "Employee Id", "Employee No", "Employee Name", "Designation", "DOJ", "DOL", "Unit", "Department", "Sub Department", "Client Branch", "Division", "Region", "City", "Province", "Territory", "Location", "Remarks", "Salary Per Month", "Current Salary", "MEAL ALLOW", "Add / Del", "OT Hours", "OT Rate", "OT Amount", "Travel Allowance", "Travel Exp.", "Sp.OT Amount", "Working Days", "Extra Days", "Extra Days Amount", "Ex-Gratia", "Other Arrears", "Hardship Allowance", "Other Exp", "Absent Days", "Absent Days Amount", "EOBI", "EOBI Employer Arrears", "Edu. CESS", "ESSI", "ESSI Arrears", "Life Ins.", "Health Insurance", "3rd Party Liab.", "Bank Charges", "Mobile Allowance", "Misc.", "LaonAdj", "Gross Total", "Service Charges", "General Sales Tax", "Billing Amount", "Refund To Client", "I.Tax", "Professional Tax", "EOBI Emp Con", "Net Salary", "EOBI Employee Arrears", "Veh Rep/Maint", "Notice Salary", "Loan Ded."})
in
    #"Expanded Excel.Data"

 

 

Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.

 

Kees Stolker

A big fan of Power Query and Excel

lbendlin
Super User
Super User

let
    Source = Folder.Files("C:\Users\xxx\Downloads"),
    ReadSheet = (xsheet)=> Table.PromoteHeaders(Table.Skip(xsheet,8), [PromoteAllScalars=true]),
    ReadFile = (xfile)=> let 
        #"Imported Excel Workbook" = Excel.Workbook(xfile),
        #"Filtered Rows1" = Table.SelectRows(#"Imported Excel Workbook", each ([Kind] = "Sheet")),
        #"Added Custom" = Table.AddColumn(#"Filtered Rows1", "Custom", each ReadSheet([Data])),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Name", "Custom"}),
        #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Name", "Sheet Name"}}),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Renamed Columns", "Custom", Table.ColumnNames(#"Renamed Columns"[Custom]{0}))
    in
        #"Expanded Custom",      
    #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Feb 2024.xlsx" or [Name] = "Jan 2024.xlsx")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each ReadFile([Content])),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Name", "Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Name", "File Name"}}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Renamed Columns", "Custom", Table.ColumnNames(#"Renamed Columns"[Custom]{0}))
in
    #"Expanded Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

@lbendlin, brother it is not working in my scenario,

Saad_Hanif456_0-1732519773849.png

 

In the third column there is error in Excel Column (why is that so?) + what if the Excel Sheet of the data is like below in of the sheets:

Saad_Hanif456_1-1732519900305.png

I have updated the files of Excel in this link. https://drive.google.com/drive/folders/16lMbD6T_DsyXE3UzYGWVuf_EwxLcRzDa?usp=drive_link 

 

Regard,
Saad Hanif

lbendlin_0-1732662860139.png

This is not a usable input format.  Find a way to avoid that.

 

Dear @lbendlin ,

The sheet is received in this format, else i have to do manual, work removing unnecessary rows. Please find out a way for it.

Regards,

Saad Hanif

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors