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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
squiddly
Advocate I
Advocate I

Replacing multiple values in multiple columns

https://community.powerbi.com/t5/Desktop/Replacing-multiple-values-in-multiple-columns/td-p/313013

 

Almost exactly like the above link, except I'm trying to only use 1 replacement table.  I know I need to remove a loop here somewhere, but not sure where!

 

#"CPE-Char-Subs-tbl-rev" is my translation table.

#"CPE-22-parsed" is the table that I need to transform.  Only need to transform the columns in the variable ColumnsToTransform.

 

let
    ColumnsToTransform = {"Vendor", "Product", "Version", "Update", "Edition"},
    TranslationLists = List.Buffer(Table.ToRows(#"CPE-Char-Subs-tbl-rev")),
    TransformSpecs = List.Buffer(List.Zip({ColumnsToTransform,TranslationLists})),
    Source = #"CPE-22-parsed",
    Replaced = 
        List.Accumulate(
            TransformSpecs,
            Source,
            (t1,r1) => 
                List.Accumulate(
                    r1{1},
                    t1,
                    (t2,r2) =>
                        Table.TransformColumns(
                            t2,
                            {r1{0}, 
                             each Replacer.ReplaceText(_,r2{0},r2{1})}
                        )
                )
        ),
    Result = Value.ReplaceType(Replaced,Value.Type(Source))
in
    Result

Thank you in advance for any pointers!

1 ACCEPTED SOLUTION
RobertSlattery
Responsive Resident
Responsive Resident

Untested but, maybe in the right direction...

 

let
    ColumnsToTransform = {"Vendor", "Product", "Version", "Update", "Edition"},
    TranslationList = List.Buffer(Table.ToRows(#"CPE-Char-Subs-tbl-rev")),
    Source = #"CPE-22-parsed",
    Replaced = 
        List.Accumulate(
            ColumnsToTransform,
            Source,
            (sourceOuter,col) => 
                List.Accumulate(
                    TranslationList,
                    sourceOuter,
                    (sourceInner,translationCouple) =>
                        Table.TransformColumns(
                            sourceInner,
                            {col, 
                             each Replacer.ReplaceText(_,translationCouple{0},translationCouple{1})}
                        )
                )
        ),
    Result = Value.ReplaceType(Replaced,Value.Type(Source))
in
    Result

View solution in original post

3 REPLIES 3
RobertSlattery
Responsive Resident
Responsive Resident

Untested but, maybe in the right direction...

 

let
    ColumnsToTransform = {"Vendor", "Product", "Version", "Update", "Edition"},
    TranslationList = List.Buffer(Table.ToRows(#"CPE-Char-Subs-tbl-rev")),
    Source = #"CPE-22-parsed",
    Replaced = 
        List.Accumulate(
            ColumnsToTransform,
            Source,
            (sourceOuter,col) => 
                List.Accumulate(
                    TranslationList,
                    sourceOuter,
                    (sourceInner,translationCouple) =>
                        Table.TransformColumns(
                            sourceInner,
                            {col, 
                             each Replacer.ReplaceText(_,translationCouple{0},translationCouple{1})}
                        )
                )
        ),
    Result = Value.ReplaceType(Replaced,Value.Type(Source))
in
    Result

That was it exactly Robert.  Thank you!  I only copied and pasted your code, will dive into it in a few minutes to understand 🙂

Greg_Deckler
Community Champion
Community Champion

@ImkeFor @MarcelBeug are probably 2 of the best people to help.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.