One Step Transfomation

yevhen

New Member
Joined
Jan 5, 2025
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
Power Query:
let
  Source = Table.CombineColumns(
  Table.TransformColumnTypes(Excel.CurrentWorkbook(){[Name="CombineColumns"]}[Content], {{"A", type text},{"B", type text},{"C", type text}}), {"A","B","C"}, Combiner.CombineTextByDelimiter("/", QuoteStyle.None), "ABC")
in
    Source

Screenshot 2025-01-06 104135.png


Hi everyone. Need help on how to figure out to make column names not hard coded but dynamic, so when new columns will be added the query would work.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
@yevhen , do you really need "one step" solution?
Power Query:
let
    one_step = ((source) => ((columns) => Table.CombineColumns(
        source, 
        columns, 
        (x) => Text.Combine(List.Transform(x, Text.From), "/"), Text.Combine(columns)
    ))
    (Table.ColumnNames(source)))(Excel.CurrentWorkbook(){[Name="CombineColumns"]}[Content])
in
    one_step
 
Upvote 0
these 2 options look simpler
Power Query:
let
    one_step = ((source) => Table.FromList(
        Table.ToList(source, (x) => {Text.Combine(List.Transform(x, Text.From), "/")}),
        (x) => x, 
        {Text.Combine(Table.ColumnNames(source))}
    )
    )(Excel.CurrentWorkbook(){[Name="CombineColumns"]}[Content])
in
    one_step
Power Query:
let
    one_step = ((source) => #table(
        {Text.Combine(Table.ColumnNames(source))}, 
        Table.ToList(source, (x) => {Text.Combine(List.Transform(x, Text.From), "/")})
    )
    )(Excel.CurrentWorkbook(){[Name="CombineColumns"]}[Content])
in
    one_step
 
Upvote 0
Solution
these 2 options look simpler
Power Query:
let
    one_step = ((source) => Table.FromList(
        Table.ToList(source, (x) => {Text.Combine(List.Transform(x, Text.From), "/")}),
        (x) => x,
        {Text.Combine(Table.ColumnNames(source))}
    )
    )(Excel.CurrentWorkbook(){[Name="CombineColumns"]}[Content])
in
    one_step
Power Query:
let
    one_step = ((source) => #table(
        {Text.Combine(Table.ColumnNames(source))},
        Table.ToList(source, (x) => {Text.Combine(List.Transform(x, Text.From), "/")})
    )
    )(Excel.CurrentWorkbook(){[Name="CombineColumns"]}[Content])
in
    one_step

Thanks a lot. It works great. Just making my first steps on understanding the M language, and I am amazed with its flexibility. But as for now, it functions as a bit of an advanced topic to me, and I am wondering if it could be implemented with the help of lists?
 
Upvote 0
Here's a solution that's mostly UI-based, with two hand-written custom columns in step 5 and 6. They make a list of specific columns from the tables generated with the Group By action.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="your_data"]}[Content],
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
    #"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Index"}, {{"All Rows", each _, type table [Index=number, Attribute=text, Value=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Row headers", each Table.Column([All Rows], "Attribute")),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Row values", each Table.Column([All Rows], "Value")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom1", {"Row headers", each Text.Combine(List.Transform(_, Text.From)), type text}),
    #"Extracted Values1" = Table.TransformColumns(#"Extracted Values", {"Row values", each Text.Combine(List.Transform(_, Text.From), "/"), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values1",{"All Rows"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[#"Row headers"]), "Row headers", "Row values"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns1"
 
Upvote 0

Forum statistics

Threads
1,225,684
Messages
6,186,424
Members
453,354
Latest member
Ubermensch22

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