Forum Discussion
Dynamic column name based on a column value coming from a different unrelated table
Hi Anonymous - Associating the columns from Table A with the values from Table B, you can do in power Query as below:
Please follow the steps:
On table B:
Do the pivot :and I named it as TableB_Pivoted
On Table A, you can perform Merge query by joining the Table A with TableB_Pivoted use left outer join
Expand all 4 columns , you can see the below image:
Click on Add Column -> Custom Column.
Name the column Column1 - Extract Date and use the following formula
TableB_Pivoted[Column1]{0}
TableB_Pivoted[Column2]{0}
TableB_Pivoted[Column3]{0}
TableB_Pivoted[Column4]{0}
Repeat this for all columns in Table A (Column2, Column3, Column4).
Perform last few steps:
Do a pivot on Table A with Selecting Column 1
do it for remaining 3 columns too
I am not able to share pbix file here, not sure how to share it here.
i will add the complete advanced query editor
Please follow the steps you can achieve the same.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Thanks rajendraongole1
I have tried to follow the steps you provided, however, I'm getting errors when applying the step - adding columns "Column1 - Extract Date". See below
It would be great if you could attach pbix so I can check where I am making mistake or if you could explian please?
Thanks
Brij
- rajendraongole12 years ago
Super User
Hi Anonymous - I am not able to attached my pbix file here,option not available.
you almost reached towards the solution.
after merge queries, during the expanding option you can remove the original prefix and continoue to add the new custom columns, it works
Check and confirm
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!- Anonymous2 years agoNot applicable
Thanks, rajendraongole1 for your help.
I was keeping the original prefix hence it was throwing an error! But after removing it I can move forward.
I am almost there. Now I can see the dates as the column header for the relevant columns however, the original column labels is not appearing along with the dates! I can see it on your last step, but how did you get it? Pleaes advise. Thanks
- rajendraongole12 years ago
Super User
Great Anonymous - if it works, mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!last step you can rename it.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!