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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

Create columns dynamically from column values

Hello community

 

I'm trying to create new columns in a table from the values in one column in the table.

 

I have a data set as it is shown below:

 

 

FromColumns.PNG

 

And I want to get new columns from the values as it is shown in red.

 

NewColumns.PNG

 

I wish to do it automatically.

 

How can I do that?

 

Thanks in advance for your time

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

In the Query Editor (M), you can select Column1 and choose "Pivot Column" on the Transform tab.

 

Maybe that is what you are looking for, however your result columns are empty and COLUMN1 is still in the result tabel.

 

"Pivot Column" typically aggregates values from another column (e.g. COLUMN2) in the new columns per value in COLUMN1, and then reduce rows so there are no duplicate combinations in the other columns (COLUMN3 and COLUMN4) in your example.

COLUMN1 as such would not be in the result table.

 

Edit: alternatively you can use the following code in the Advanced Query Editor, in which "TableName" is the name of the previous step:

    AddedColumns = Table.SelectColumns(TableName,List.Union({Table.ColumnNames(TableName),List.Distinct(TableName[COLUMN1])}), MissingField.UseNull)

 

 

Specializing in Power Query Formula Language (M)

View solution in original post

3 REPLIES 3
MarcelBeug
Community Champion
Community Champion

In the Query Editor (M), you can select Column1 and choose "Pivot Column" on the Transform tab.

 

Maybe that is what you are looking for, however your result columns are empty and COLUMN1 is still in the result tabel.

 

"Pivot Column" typically aggregates values from another column (e.g. COLUMN2) in the new columns per value in COLUMN1, and then reduce rows so there are no duplicate combinations in the other columns (COLUMN3 and COLUMN4) in your example.

COLUMN1 as such would not be in the result table.

 

Edit: alternatively you can use the following code in the Advanced Query Editor, in which "TableName" is the name of the previous step:

    AddedColumns = Table.SelectColumns(TableName,List.Union({Table.ColumnNames(TableName),List.Distinct(TableName[COLUMN1])}), MissingField.UseNull)

 

 

Specializing in Power Query Formula Language (M)

I have to bind values to slicer based on value selection in another slicer. For achieving this  I am getting data from different table but if i choose value in slicer that is not reflecting in all the visuals of report.

MarcelBeug
Community Champion
Community Champion

@Deepa that looks like something completely different, so why not just start a new topic?

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.