Search code examples
powerbim

How to solve Expression.Error in this code


I have this M code, where I try to set this condition: when create_to_launch contains char d, then I'll only take the first value of its string. But, when it does not contain it, I'll take the first 3. However I'm getting an error, and I cannot find it:

let

    #"Columna cambiada5" = Table.ReplaceValue( #"Columna cambiada4" ,each "create_to_launch",
    each if Text.Contains(_, "d") then Table.TransformColumns(#"Columna cambiada4", 
    {{"create_to_launch", each Text.Start(_, 1)}}) 
    else "create_to_launch", Table.TransformColumns(#"Columna cambiada4",{{"create_to_launch", 
    each Text.Start(_, 1)}}))

in  #"Columna cambiada5"

/* Error */
Expression.Error: Passed 4 arguments to a function that waits 5.
Details:
Pattern=
Arguments=[List]

Solution

  • i create some dummy data

    = Table.AddColumn(Source, "Custom", each if Text.Contains([Region], "d") then Text.Range([Region],0,1) else Text.Range([Region],0,3))
    

    enter image description here