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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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