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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
skhalatian
Frequent Visitor

M query extract Excel worksheet name

Hi,

 

- I have a function for merging few XL speadsheets

- each spreadsheet has got one worksheet ( the worksheet name for all speedsheets are the same (WS))

 

the function works as expected, the issue is that if I have a spreadsheet with worksheet  named different than WS then it will break

 

I want to be able to load XL file that have one worksheet and the function merge them regardless of the name of the worksheet

 

currenly I'm using the folloing code

 

 

let
    Source = (#"Sample File Parameter1") => let
        Source = Excel.Workbook(#"Sample File Parameter1", null, true),
        WS_Sheet = Source{[Item="WS",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(WS_Sheet , [PromoteAllScalars=true])
    in
        #"Promoted Headers"
in
    Source

Thanks

Shaun

1 REPLY 1
v-fengyz-msft
Helper I
Helper I

@shaun,

 

If one spreadsheet only has one worksheet or the worksheet you required always occurred in fixed location of multiple worksheets (e.g. always the first worksheet ), then you can exact the data

 

of worksheet using below sample code:

 

let

    Source = (#"Sample File Parameter1") => let

 

        Source = Excel.Workbook(File.Contents(#"Sample File Parameter1"), true),

 

       //this line return data of first worksheet and ignore the name of worksheet

 

       WS_Sheet = Table.SelectRows(Source, each [Kind] = "Sheet"){0}[Data],

 

        #"Promoted Headers" = Table.PromoteHeaders(WS_Sheet, [PromoteAllScalars=true])

    in

        #"Promoted Headers"

in

Source

 

 

If not, please share some logics to meet your requirement.

 

Regards,

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors