Search code examples
power-automate

Getting "The expression is invalid" in compose of power automate


I was trying to remove last character(comma) from my variable Images in power automate using compose action as below using expression.

if(endsWith(variables('Images'), ','), substring(variables('Images'), 0, length(variables('Images')) - 1), variables('Images'))

But when I click OK button in expression it always saying "The expression is invalid". but I don't know what is the problem there. Below is flow image. enter image description here


Solution

  • Yeah, you can't do something - 1, it's all expression based so you need to use the sub() function.

    This will work for you ...

    if(endsWith(variables('Images'), ','),
      substring(variables('Images'), 0, sub(length(variables('Images')), 1)),
      variables('Images')
    )