Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Set an IF for different dates

My table follows this structure:

datecolumn1column2
02/01/2020 111222
03/03/2020222777
07/10/2020333555
12/12/2020444999

 

I want to create a new column that, if the date is less than 05/05/2020, then the values will be taken from column1. If the date is greater than 05/05/2020, the value will be taken from column2.

 

The expected result would look like this:

datecolumn1column2new_column
02/01/2020 111222111
12/12/2020222777777
07/10/2020333555555
04/04/2020444999444

 

  • HI Anonymous ,

     

    NEW_COLUMN = IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2])

5 Replies

  • Anonymous , Try like

     

    new column = IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2])

    new measure = IF(max('Table'[date]) < DATE(2020,5,5), max('Table'[column1]), max('Table'[column2]))

    new measure = sumx('Table', IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2]))

  • camargos88's avatar
    camargos88
    Icon for Community Champion rankCommunity Champion

    HI Anonymous ,

     

    NEW_COLUMN = IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2])
  • HI Anonymous ,

     

    You can create a calculated column as follows:

     

    NewValueCol = IF(Tablename[date] < DATE(2020, 05, 05), Tablename[Column 1], Tablename[Column 2])

     

    Replace Tablename[date] in above DAX with your table and column.

     

    Thanks,

    Pragati

  • Anonymous's avatar
    Anonymous
    Not applicable

    camargos88 
    Pragati11 
    amitchandak 
    Thanks to everyone for the quick responses! Worked perfectly!

    Just a small question before closing the topic: is it possible to insert Hour in this DATE function too? In case I wanted to get values ​​from a specific day and time?