Creating list of all columns used/named

johnny51981

Active Member
Joined
Jun 8, 2015
Messages
366
Hello:
I have found this query, which works perfectly at giving me the ability to look at all of the queries currently built.
Power Query:
let
    Source = #sections,
    Section1 = Source[Section1],
    convertTable = Record.ToTable(Section1)
in
    convertTable

Does anyone know how to update the convertTable step to also use headers as first row, and then delete everything but that first row?

The queries that I have built are linked to different Smartsheets and I'm trying to verify if each sheet is built the same.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This enough? Afterwards you could expand the "Value" column for all used headernames.

Power Query:
let
    Source = #sections,
    Section1 = Source[Section1],
    Section2 = Record.RemoveFields(Section1,{"Query1"}),  //filter out current query
    convertTable = Record.ToTable(Section2),
    result = Table.TransformColumns(convertTable,{{"Value", each Table.ColumnNames(Table.PromoteHeaders(_))}})
in
    result
 
Last edited:
Upvote 0
This enough? Afterwards you could expand the "Value" column for all used headernames.

Power Query:
let
    Source = #sections,
    Section1 = Source[Section1],
    Section2 = Record.RemoveFields(Section1,{"Query1"}),  //filter out current query
    convertTable = Record.ToTable(Section2),
    result = Table.TransformColumns(convertTable,{{"Value", each Table.ColumnNames(Table.PromoteHeaders(_))}})
in
    result
Not enough. I'm looking to have something like this, which is the final result I was able to build...though not dynamic as I was hoping.
1710777079285.png


Here is the M Code for one sheet:
Power Query:
let
    Source = #"Smartsheet 1",
    #"Kept First Rows" = Table.FirstN(Source,1),
    #"Added Query Name" = Table.AddColumn(#"Kept First Rows", "Smartsheet", each "Smartsheet 1", type text),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Query Name",{"Smartsheet"}),
    #"Added Smartsheet Index" = Table.AddIndexColumn(#"Removed Other Columns", "Smartsheet Index", 0, 1, Int64.Type),
    #"Demoted Headers" = Table.DemoteHeaders(#"Kept First Rows"),
    #"Kept First Rows1" = Table.FirstN(#"Demoted Headers",1),
    #"Demoted Headers1" = Table.DemoteHeaders(#"Kept First Rows1"),
    #"Transposed Table" = Table.Transpose(#"Demoted Headers1"),
    #"Sorted Rows" = Table.Sort(#"Transposed Table",{{"Column2", Order.Ascending}}),
    #"Added Column Index" = Table.AddIndexColumn(#"Sorted Rows", "Column Index", 1, 1, Int64.Type),
    #"Merged Queries" = Table.NestedJoin(#"Added Column Index", {"Column Index"}, #"Added Smartsheet Index", {"Smartsheet Index"}, "Added Column Index", JoinKind.FullOuter),
    #"Expanded Added Column Index" = Table.ExpandTableColumn(#"Merged Queries", "Added Column Index", {"Smartsheet", "Smartsheet Index"}, {"Smartsheet", "Smartsheet Index"}),
    #"Added Column Number" = Table.AddColumn(#"Expanded Added Column Index", "Column Number", each "Column"&Number.ToText(List.Max({[Column Index], [Smartsheet Index]})), type text),
    #"Added Column Header" = Table.AddColumn(#"Added Column Number", "Column Header", each if [Smartsheet Index] = 0 then "Smartsheet Name" else [Column2], type text),
    #"Added Used" = Table.AddColumn(#"Added Column Header", "Used", each if [Smartsheet Index] = 0 then [Smartsheet] else "Yes", type text),
    #"Removed Other Columns1" = Table.SelectColumns(#"Added Used",{"Column Number", "Column Header", "Used"}),
    #"Transposed Table1" = Table.Transpose(#"Removed Other Columns1"),
    #"Removed Top Rows" = Table.Skip(#"Transposed Table1",1),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true])
in
    #"Promoted Headers"

And then Appended them all together in one query, which gave me the results I provided the picture of.

Any thoughts on streamlining it/simplifying it would be appreciated.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top