Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Expression.SyntaxError: Token RightParen expected. // Needing Help with a custom function

Hi there, so i'm writing this simple code to help me out with a problem when dealing with a Sheet..

 

So i have this 8 format number like this for example : 04777020 where i need to convert into a Postal code format like this 04777-020

But the thing is, some of the numbers lost the 0 which can usually be in front of the Postal Code, leaving it only with length of 7... soo i need to add this 0 again in the front of the code and i Need to add the 0 and add the - after the number in the 5th position, how can i do it?

 

Until now i writed this

 

= Table.AddColumn(#"Changed Type1", "Custom", each if Text.Length([CEP]) = 8 then Text.Insert([CEP],5,"-") else Text.Insert([CEP],1,"0")

 

ChangedType 1 is where i changed the column format to Text and [CEP] is where my codes are. and this error is showing up

 

Expression.SyntaxError: Token RightParen expected.

 

 

 

 

  • johnt75's avatar
    johnt75
    4 years ago

    It needs to go at the very end of the line, not in the middle

6 Replies

  • You're missing the ) at the very end to close the Table.AddColumn function

    • Anonymous's avatar
      Anonymous
      Not applicable

      it still shows the error and now at the added ( 

       

      • johnt75's avatar
        johnt75
        Super User

        It needs to go at the very end of the line, not in the middle

  • HotChilli's avatar
    HotChilli
    Community Champion

    We've all done it and you're going to kick yourself when you solve it.

    If I said Right paren means right bracket or closing bracket ......

    ---

    As to the algorithm, I have 2 suggestions:

    1. Maybe use Add column  ->Column from examples  to see if powerbi can help.

    2. If you don't get it that way, have a look at Text.PadStart() function

     

    Good luck

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for your reply, i'll have a look in your sugestions and about the sugestions

       

      1 - Soo.. i've tried the column from examples and it kinda worked for some values, but not for all fo them. Most because there are some codes that start with 2 zeros.. or 3, or 4 or even that start with 0 and then add a normal number like 1... soo it creates a lot of variants that PBI cant figure out what to do since if it starts with an 0 he automatically discart the number. Also, I could adapt all these variants one by one, but the problem is that pbi in this add column by examples have a limited visualization where i cant solve all of these

       

      2 - the point is using Text.PadStart instead of Text.Insire?

  • Hola,

     

    Tengo la siguiente consulta con el error " Se esperaba el token RightParen" en la coma marcada en rojo. Por favor ayúdenme a resolverlo.

     

    la consulta es:

     

        Origen = Odbc.DataSource("dsn=IWS", [HierarchicalNavigation=true]),

        dbo_Schema = Origen{[Nombre="dbo",Kind="Esquema"]}[Datos],

        Ges_OrdenesCompra_Table = dbo_Schema{[Nombre="Ges_OrdenesCompra",Kind="Tabla"]}[Datos],

        Table.SelectRows = (Ges_OrdenesCompra_Table ,  cada [dato] >= #datetime(2022, 1, 1, 0, 0,0)),

        Table.SelectColumns = (Filas filtradas, {"VendAccount", "VendName"})

     

        Columnas filtradas