Error using two lookup output in a if statement in foreach loop

Amit Trivedi 40 Reputation points
2023-09-25T20:18:00.1866667+00:00

I am trying to loop through the output of one of the two Lookup activity in a ForEach loop based on a condition. For this I am using a if statement as given below:

@if(equals(variables('PreviousExecutionFlag'),0),activity('Control Table for all tables').output.value,activity('Lookup2').output.value)
																						

I am getting below error:

"The expression 'length(if(equals(variables('PreviousExecutionFlag'),0),activity('Control Table for all tables').output.value,activity('Lookup2').output.value)

)' cannot be evaluated because property 'output' cannot be selected."

I have used

@activity('Lookup2').output.value

in a for each loop and it works fine but when using in a if condition, it doesn't work.

Please help .

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,709 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. AnnuKumari-MSFT 32,906 Reputation points Microsoft Employee
    2023-09-26T09:24:10.27+00:00

    Hi Amit Trivedi ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your question here.

    As per my understanding you are trying to use if expression in ADF pipeline to check if value of a variable is equal to 0 or not. In case if it's equal to 0, then return the output value from first lookup activity else return the output value from second lookup activity.

    First of all, the expression which you have shared doesn't have length property , however, in the error message , we can see the expression is supposed to return the length of the output array after evaluating the if condition. Could you please cross check that and remove length from the expression. Also, if possible kindly share the screenshot of your pipeline.

    I would suggest you to create an additional variable of type 'array' and use a set variable activity before foreach and store the output array of 'if expression ' into that variable and then in the foreach point to that variable as item.

    User's image

    Hope it helps. Kindly accept the answer by clicking `Accept answer


  2. AnnuKumari-MSFT 32,906 Reputation points Microsoft Employee
    2023-09-26T09:24:34.8733333+00:00

    Hi Amit Trivedi ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your question here.

    As per my understanding you are trying to use if expression in ADF pipeline to check if value of a variable is equal to 0 or not. In case if it's equal to 0, then return the output value from first lookup activity else return the output value from second lookup activity.

    First of all, the expression which you have shared doesn't have length property , however, in the error message , we can see the expression is supposed to return the length of the output array after evaluating the if condition. Could you please cross check that and remove length from the expression. Also, if possible kindly share the screenshot of your pipeline.

    I would suggest you to create an additional variable of type 'array' and use a set variable activity before foreach and store the output array of 'if expression ' into that variable and then in the foreach point to that variable as item.

    User's image

    Hope it helps. Kindly accept the answer by clicking Accept answer button. Thankyou

    0 comments No comments

  3. Amit Trivedi 40 Reputation points
    2023-09-26T14:10:37.38+00:00

    Thanks for your reply.

    I forgot to mention, I am not using length() anywhere in my pipeline but still it is showing in the error.


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.