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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
coejnot
Frequent Visitor

Substiute multiple values in a text from another table

Hi, 

I have this string in a column:

 

A*B*C*A*C

 

Then I have this table:

CodeDescription
ABlue
BGreen
CRed
D

Yellow


I would like to create a column where the result picks the description from the table. 

The result should be like this:

Blue*Green*Red*Blue*Red

 

I would really appreciate if you could help me with a dax for this.

 

Thanks!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@coejnot 

You can add a custom column in Power Query and achieve the same. File is attached

 

 

   Text.Combine(
    List.Transform(
    Text.Split([Column1],"*"),(a)=> Text.Replace(a,a, Table.SelectRows( Table2, (i)=> i[Code] = a)[Description]{0})),"*")
    )

 

 

Fowmy_0-1628601477861.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
Fowmy
Super User
Super User

@coejnot 

You can add a custom column in Power Query and achieve the same. File is attached

 

 

   Text.Combine(
    List.Transform(
    Text.Split([Column1],"*"),(a)=> Text.Replace(a,a, Table.SelectRows( Table2, (i)=> i[Code] = a)[Description]{0})),"*")
    )

 

 

Fowmy_0-1628601477861.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

coejnot
Frequent Visitor

This worked really well, thank you!

@coejnot I realize that this is already solved and @Fowmy solution is the best one. However, I couldn't help creating a DAX solution for this. The solution is based on my Text to Table measure:

Column = 
    VAR __Separator = "*"
    VAR __SearchText = [Column1]
    VAR __Len = LEN(__SearchText)
    VAR __Count = __Len - LEN(SUBSTITUTE(__SearchText,__Separator,"")) + 1
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                GENERATESERIES(1,__Count,1),
                "__Word",
                    VAR __Text = SUBSTITUTE(__SearchText,__Separator,"|",IF([Value]=1,1,[Value]-1))
                    VAR __Start =
                        SWITCH(TRUE(),
                            __Count = 1,1,
                            [Value] = 1,1,
                            FIND("|",__Text)+1
                        )
                    VAR __End = 
                        SWITCH(TRUE(),
                            __Count = 1,__Len,
                            [Value] = 1,FIND("|",__Text) - 1,
                            [Value] = __Count,__Len,
                            FIND(__Separator,__Text,__Start)-1
                        )
                    VAR __Word = MID(__Text,__Start,__End - __Start + 1)
                RETURN __Word
            ),
            "__Replaced",LOOKUPVALUE('Table'[Description],'Table'[Code],[__Word])
        )
RETURN
    CONCATENATEX(__Table,[__Replaced],__Separator,[Value])

 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi, @Greg_Deckler 

I tried this out too, and it also works as I expected. 

Interesting to learn even more about how to create things in DAX. 

Thank you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.