skip to Main Content

I Have question about Azure Data Factory Expression for function IF

in SQL we can create using

CASE WHEN 'A' Then 1
     when  'B' then 2
     when 'C' then 3
else 100

is this correct expression to IF?

@if(equals(variables('varInput'), 'a'), 'Ax', 
if(equals(variables('varInput'), 'b'), 'Bx', 'C'))

how to us "IF" function for more than 2 or we can use another Function like "Or"?

this is the expression that i built

@if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MMdd'),'0101'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(getPastTime(1,'Year'),'SE Asia Standard Time'),'yyyy'),'/','12'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')), if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'dd'),'01'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Month'),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')),concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')))

I want to create folder base on this case

  1. If today’s date is 2023-01-01 then folder name path will be PRODUCT/2022/12/20221231
  2. if today’s date is 2023-02-01 then folder name path will be PRODUCT/2023/01/20230131
  3. if todays date is 2023-03-02 then folder name path will be PRODUCT/2023/03/20230301

but expression IF doest support more than 2 arguments

2

Answers


  1. Check the case function as well, this should be the one you are looking for, not if function.

    https://learn.microsoft.com/en-us/azure/data-factory/data-flow-expressions-usage#case

    please also confirm if this answer helped you

    Login or Signup to reply.
  2. IF doesn’t support more than 2 arguments.

    In order to give multiple conditions, you can use the nested if expression i.e. if expression inside another if .

    I used the same expression what you have tried and got error.

    This error is because, closing paranthesis ) are misplaced in that expression. I have highlighted that in the below image.

    enter image description here

    Corrected expression :

    You can use the below expression for your requirement.

    @if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MMdd'),'0101'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(getPastTime(1,'Year'),'SE Asia Standard Time'),'yyyy'),'/','12','/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')), if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'dd'),'01'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Month'),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')),concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd'))))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search