Subracting the Values in 2 Strings in an ADF Expression

Mike Kiser 1,536 Reputation points
2021-04-25T02:34:25.753+00:00

Hello! This one stumped me. @Nasreen Akter @MartinJaffer-MSFT

I have one String that is say 40
Then I need another String that is 100-40 = 60
The first String which is equal to 40 is stored in the DB Table as an nvarchar(max)

I tried :
@sub (100,variables('VirtualHours'))

but I get: Expression of type: 'Int' does not match the field: 'value'

Any suggestions?

Thanks
Mike Kiser

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

2 answers

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,642 Reputation points Microsoft Employee Moderator
    2021-04-26T04:30:29.12+00:00

    Hi @Mike Kiser ,

    Thanks for reaching out.

    As per your description, I assume your variable variables('VirtualHours') is a string type , if that is the case then please try --> @sub(100, int(variables('VirtualHours'))).
    As the function sub expects its parameters to be an integer or a decimal number, you will have to convert the parameter value of type String to int.

    In case if you are storing/assigning the output of this expression to a string type variable/parameter then please try this expression --> @string(sub(100, int(variables('VirtualHours')))).

    Hope this helps. Do let us know how it goes.

    Thanks

    ----------

    Please don’t forget to Accept Answer and Up-Vote wherever the information provided helps you, this can be beneficial to other community members.


  2. KranthiPakala-MSFT 46,642 Reputation points Microsoft Employee Moderator
    2021-04-26T17:05:19.103+00:00

    Hi @Mike Kiser ,

    If you are using the expression in your IF Condition activity, please try this --> @greater(sub(100, int(variables('VirtualHours'))), 0)

    Do let us know how it goes.

    Thank you

    ----------

    Please don’t forget to Accept Answer and Up-Vote wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.