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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Sayri
Helper I
Helper I

How to extract all the column names from a 'Table' data Type Column ?

Hi all,
Would it be possible to extract all the column names + 1st row, from each Table listed in 'Data' Column below please ?


2020-12-29 19-37-41.png
The goal would be to have a list like:

Index0.Column01, 1st row Value
Index0.Column02, 1st row Value
Index0.Column03, 1st row Value
Index1.Column1, 1st row Value
Index1.Column2, 1st row Value
Index1.Column3, 1st row Value
Index2.ColumnA, 1st row Value
Index2.ColumnB, 1st row Value
Index2.ColumnC, 1st row Value
Index2.ColumnD, 1st row Value
Index3.Column1a, 1st row Value
Index3.Column2b, 1st row Value
Etc...

2 ACCEPTED SOLUTIONS
CNENFRNL
Community Champion
Community Champion

Hi, @Sayri , it's easy to extract all columns' names from each table in your scenario; you might add applied steps like this,

 

#"Column Names" = Table.TransformColumns(#"Previous Step", {{"Data", Table.ColumnNames}}),
#"Expanded Data" = Table.ExpandListColumn(#"Column Names", "Data")

 


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!

View solution in original post

Jimmy801
Community Champion
Community Champion

Hello @Sayri 

 

you can transform you tables first to get the first row of your tables as new table with Table.First and Record.ToTable.

Then expand the newly created table. here an easy example

 

let
    Source = #table({"Index", "Data"}, {{"Index0", #table({"ColumnA", "ColumnB"}, {{"A", "B"}, {"C", "D"}})}, {"Index1", #table({"Column1", "Column2"}, {{"E", "F"}, {"G", "H"}})}}),
    GetFirstRowOfTable = Table.TransformColumns
    (
        Source,
        {
            {
                "Data",
                each Record.ToTable(Table.First(_))
            }
        }
    ),
    #"Expanded Data" = Table.ExpandTableColumn(GetFirstRowOfTable, "Data", {"Name", "Value"}, {"Column name", "First row value"})
in
    #"Expanded Data"

Jimmy801_0-1609319855134.png

 

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

5 REPLIES 5
Jimmy801
Community Champion
Community Champion

Hello @Sayri 

 

you can transform you tables first to get the first row of your tables as new table with Table.First and Record.ToTable.

Then expand the newly created table. here an easy example

 

let
    Source = #table({"Index", "Data"}, {{"Index0", #table({"ColumnA", "ColumnB"}, {{"A", "B"}, {"C", "D"}})}, {"Index1", #table({"Column1", "Column2"}, {{"E", "F"}, {"G", "H"}})}}),
    GetFirstRowOfTable = Table.TransformColumns
    (
        Source,
        {
            {
                "Data",
                each Record.ToTable(Table.First(_))
            }
        }
    ),
    #"Expanded Data" = Table.ExpandTableColumn(GetFirstRowOfTable, "Data", {"Name", "Value"}, {"Column name", "First row value"})
in
    #"Expanded Data"

Jimmy801_0-1609319855134.png

 

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Actually I've done a mix between your solution and the previous from @CNENFRNL  and it works perfectly
Thank you very much to both of you

wdx223_Daniel
Super User
Super User

=#table(2,List.Combine(Table.ToList(PreviousStep,each List.Transform(Table.ColumnNames(_{1}),(x)=>Number.ToText(_{0},"Index0.")&x&","&Record.FieldOfDefault(_{1}{0},x,null)))))

CNENFRNL
Community Champion
Community Champion

Hi, @Sayri , it's easy to extract all columns' names from each table in your scenario; you might add applied steps like this,

 

#"Column Names" = Table.TransformColumns(#"Previous Step", {{"Data", Table.ColumnNames}}),
#"Expanded Data" = Table.ExpandListColumn(#"Column Names", "Data")

 


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!

Thanks a lot @CNENFRNL , your solution works perfectly to list the column names 🙂
Is there any possibility to extract the 1st value of each colomn for each table please ?

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors