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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Concatenate columns where column name is dynamic

I am trying to solve the problem of having joins between tables being dynamic.

To do this my thinking is that the join would be based on a column called uniquID but that column itself will be the result of a DAX formula.

 

The DAX formula needs to do a look up on another table to find out what are the fields that make up the unique ID and then go back to the main table, find those columns, and do a concatenation to come up with the uniqueID.

 

Is this possible?

 

Update:

 

Sample data below. I want to create the UniqueID column using DAX, The DAX needs to do a look up to a setttings table to determine which fields it should concaternate. There are two ways I could think of, of laying out the setttings table.

 

Main Table

 

ABCDUniqueID
1231CD11231D1
1231CD21231D2
4562CD34562D3
4562CD14562D1

 

Settings Table

TableUniqueID fields
MainTableA
MainTableB
MainTable

D

 

 

Alternative settings table

TableUniqueFIeld1UniqueFIeld2UniqueFIeld3UniqueFIeld4UniqueFIeld5
MainTableABD  
3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi, @Anonymous

Based on my test, you could try this way as below:

Step1:

In Edit Queries, Add an index column for main table and then duplicate the main table.

Step2:

Select column A, B, C, D column Then unpivot it.

6.JPG

Step3:

Merge it with the settings table by Attribute column

7.JPG

Step4:

Expand the table and filter null value

8.JPG

Step5:

Close&Apply

Then create the relationship between main table and dup main table

9.JPG

Step6:

Use this formula to add a calculate column

UniqueID = CONCATENATEX(RELATEDTABLE('Dup Main table'),'Dup Main table'[Value],,'Dup Main table'[Attribute])

Result:

 

11.JPG

 

here is pbxi file, please try it.

 

 

Best Regards,

Lin

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks - I finally got round to reviewing this solution, I think it might work but the duiplication of the main table is not ideal, especialyl if the main table is rather large. Wil see if I can find any better solution else will awrd this the points.

Greg_Deckler
Super User
Super User

Maybe. Sample/example data would really help here. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.