Forum Discussion

coreych's avatar
coreych
Regular Visitor
3 years ago

If then statement, invalid identifier

Hi all, I'm working with a database of baseball players.  I need to match the contracts in my fantasy baseball league with the season projections I want for each player.  The season projections database has a unique identifier, but the contracts do not.  I've matched virtually every player using their name, but my method created a few duplicates.  I just need to force feed the correct player ID in the season projections into a couple of players who did not match correctly using their name.  I created the following query to replace the matching player's ID with the correct one.

 

    #"Replaced Value" = Table.ReplaceValue(#"Removed Columns", each [PlayerIDs.IDFANGRAPHS], each if [Index] = “296” then “16942” else [PlayerIDs.IDFANGRAPHS], Replacer.ReplaceText, {"Player IDs.IDFANGRAPHS"}),

 

Index refers to the index column I created to identify the players with the same name as separate players, the player I want to change is 296, I need to change that player's fangraphs ID to 16942.  This returns a "Invalid Identifier" error on the 296 parameter.  What is the invalid identifier error exactly and how can I get it to go away and run my player ID replacement?

16 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

     #"Replaced Value" = Table.ReplaceValue(#"Removed Columns", each [#“PlayerIDs.IDFANGRAPHS”], each if [Index] = “296” then “16942” else [#“PlayerIDs.IDFANGRAPHS”], Replacer.ReplaceText, {"Player IDs.IDFANGRAPHS"})

    • coreych's avatar
      coreych
      Regular Visitor

      Thanks for the help.  That code returned the same error, but it is now on the first "Player IDs.IDFANGRAPHS" parameter.

      • jbwtp's avatar
        jbwtp
        Memorable Member

        Hi coreych,

         

        You are not passing [Index] in this case, so when you are trying to use it PBI does not like it (cause it is not part of the context for the replacer funciton).

        In your case, I think, it should be something like this (I am overloading the replacer function rather than the third parameter):

         

         

        #"Replaced Value" = Table.ReplaceValue(#"Removed Columns", each [Index], null, (x,y,z)=> if y = "296" then "16942" else x, {"Player IDs.IDFANGRAPHS"})

         

         

         

  • coreych's avatar
    coreych
    Regular Visitor

    All I want to do is replace one player's fangraphs ID (currently 27646) with 16942.  There are two players with the same name who are listed as having fangraphs ID 27646, I need one of those two to change to 16942.

  • Just stumbled on this after a similar error. Mine was giving me the same error for referring to a column in the format [Name - Custom]. I think it didn't like the hyphen in the column header. It was solved by changing the reference to [#"Name - Custom"].