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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Using different table in conditional column

I need to organize a column into separate columns based on a different reference table and I'm having a hard time figuring it out in PQ.

 

Example:

OriginalColumn1Column2
AA 
BB 
C C
D D

 

Column1 and Column2 are part of another table that looks like this:

Colum1Column2
AC
BD

 

Each time "A" appears in the Original column then the contents should be copied into Column1 and so on. Each cell below the column header is named so I'm able to reference it later. e.g. cell with "A" is named Column1.1

 

I used a conditional column to do this, but I'm having a hard time referencing the second table in the code. 

 

= Table.AddColumn(#"Changed Type", "Column1", each if Text.Contains([Original], Column1.1) then "01_"& Column1.1 else null)

 

Any help is much appreciated!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

I don't understand. For example:

"Each time "A" appears in the Original column then the contents should be copied into Column1 and so on."

What do you mean "and so on?" You gave one example. I cannot extrapolate from that, other than to put everything in column 1.

 

Cells don't exist in Power Query or Power BI like they do in Excel, so you cannot name a cell Column1.1, or anything else, so I'm not clear on that either. Columns can be named - must be named. Rows cannot be named, or individual datapoints in a row or column.

 

But let me take a few guesses. You have this:

 
 

2020-12-28 13_00_08-Untitled - Power Query Editor.png

And you want to return this:

 

2020-12-28 13_00_52-Untitled - Power Query Editor.png

First thing I did was unpivoted your 2nd table

2020-12-28 13_01_52-20201228 - Pivoting Columns - Power Query Editor.png

so it becomes this - I left the default column names. You just select both columns then select Unpivot Columns.

2020-12-28 13_02_28-20201228 - Pivoting Columns - Power Query Editor.png

Then I merged taht into table 1 connecting the Original and Values columns, then expanded both columns:

2020-12-28 13_03_18-20201228 - Pivoting Columns - Power Query Editor.png

Then I pivoted the Attribute column with the following settings - Click the Attribute column, then in the Transform ribbon, the Pivot Column button - you must stop the aggregation as I have done below.

2020-12-28 13_03_47-.png

You can see my full PBIX file here. The null values will look blank when you load them into Power BI.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

2 REPLIES 2
mussaenda
Super User
Super User

Hi @Anonymous,

 

did @edhans solve your problem?

if not please show your expected output.

Thanks!

edhans
Super User
Super User

I don't understand. For example:

"Each time "A" appears in the Original column then the contents should be copied into Column1 and so on."

What do you mean "and so on?" You gave one example. I cannot extrapolate from that, other than to put everything in column 1.

 

Cells don't exist in Power Query or Power BI like they do in Excel, so you cannot name a cell Column1.1, or anything else, so I'm not clear on that either. Columns can be named - must be named. Rows cannot be named, or individual datapoints in a row or column.

 

But let me take a few guesses. You have this:

 
 

2020-12-28 13_00_08-Untitled - Power Query Editor.png

And you want to return this:

 

2020-12-28 13_00_52-Untitled - Power Query Editor.png

First thing I did was unpivoted your 2nd table

2020-12-28 13_01_52-20201228 - Pivoting Columns - Power Query Editor.png

so it becomes this - I left the default column names. You just select both columns then select Unpivot Columns.

2020-12-28 13_02_28-20201228 - Pivoting Columns - Power Query Editor.png

Then I merged taht into table 1 connecting the Original and Values columns, then expanded both columns:

2020-12-28 13_03_18-20201228 - Pivoting Columns - Power Query Editor.png

Then I pivoted the Attribute column with the following settings - Click the Attribute column, then in the Transform ribbon, the Pivot Column button - you must stop the aggregation as I have done below.

2020-12-28 13_03_47-.png

You can see my full PBIX file here. The null values will look blank when you load them into Power BI.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors