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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors