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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
webportal
Impactful Individual
Impactful Individual

Power query function to expand the first table of a workbook

I have a bunch of Excel workbooks with a table in them.

Some tables have the name "Table1", while some others have another name.

 

Power Query built a function like:

let
    Source = (Parameter1) => let
        Source = Excel.Workbook(Parameter1, null, true),
        Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data]
    in
        Table1_Table
in
    Source

 

Which is breaking in the cases where the table has a different name.

 

How do I adapt this code to get the first table it finds within the workbook irrespective of the name?

 

Thanks!

 

 

1 ACCEPTED SOLUTION

let
    Source = (Parameter1) => let
        Source = Excel.Workbook(Parameter1, null, true),
        Table1_Table = Table.SelectRows(Source, each ([Kind] = "Table"))[Data]{0}
    in
        Table1_Table
in
    Source

View solution in original post

5 REPLIES 5
webportal
Impactful Individual
Impactful Individual

@AlienSxthat's it, thank you!

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1679927074953.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

webportal
Impactful Individual
Impactful Individual

@AlienSxthanks for helping!

The Excel object contains multiple objects, like sheets, named ranges and tables.

By 1st table, I mean, whatever name it is, I want the first it finds, because I know that each file contains only one.

let
    Source = (Parameter1) => let
        Source = Excel.Workbook(Parameter1, null, true),
        Table1_Table = Table.SelectRows(Source, each ([Kind] = "Table"))[Data]{0}
    in
        Table1_Table
in
    Source
AlienSx
Super User
Super User

Hello, @webportal what is "first table"? Run 

Excel.Workbook(Parameter1, null, true)

with some Parameter1 value. You get the list of items in that workbook. Okay, filter "Kind" column to get tables only. How do pick "first" table? What is it? 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors