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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TCpowerbi
New Member

Token Comma expected

Hello all,

 

Can you please help with below.

I am trying to get below code to work but I keep getting error Token Comma expected. I have checked other discussions and the error seems to be regarding the "[counter] +1] " in line 0008.

 

Appreciate any help.

 

Regards Tommy

 

(x as text) as text =>
let
    maxIterations = Table.RowCount(BulkTextReplace),
    Iterations = List.Generate( () =>
                [Result=Text.Replace(x, BulkTextReplace[Old Value]{0}, BulktextReplace[Replace]{0}), Counter = 0],
                     each [Counter] < maxIterations,
                     each [Result = Text.Replace([Result], BulkTextReplace([Result], BulkTextReplace[Old Value]{Counter}, BulkTextReplace[Replace]{Counter}),
                    Counter = [Counter]+1], each [Result]),
    output = Iterations(maxIterations-1)
in
   output

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

Hi, @TCpowerbi , you might want to try a direct call to List.Accumulate() to accomplish the same task,

List.Accumulate(
    Table.ToRecords(BulktextReplace),
    str,
    (s,c) => Text.Replace(s, Text.From(c[Old Value]), Text.From(c[Replace]))
)

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

PhilipTreacy
Super User
Super User

Hi @TCpowerbi 

There was some incorrect syntax and a few issues with brackets, you were missing the closing ) for List.Generate. 

In addition you had 4 parameters for the second call to Text.Replace but it only takes 3.

This is syntactically correct but may not do what you were intending.

You are using List.Generate to build a list made of the values in Result, but you are trying to create an output value from Iterations(maxiterations -1) ?

 

 

(x as text) as text =>
let
    maxIterations = Table.RowCount(BulkTextReplace),
    Iterations = List.Generate
    
    ( 
        
            () =>
            
            [Result=Text.Replace(x, BulkTextReplace[Old Value]{0}, BulktextReplace[Replace]{0}), Counter = 0],

            each [Counter] < maxIterations,

            each [Result = Text.Replace([Result], BulkTextReplace[Old Value]{Counter}, BulkTextReplace[Replace]{Counter}), Counter = [Counter]+1],

            each [Result]
    )
    
in

   Iterations

 

 

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


HotChilli
Super User
Super User

I can't debug it from this side.  It looks like the square brackets are used too liberally and not in pairs.

Go through it line by line.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.