Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Adding column when Date is more than 21 days old

Hello.    I have a table names Contacts, and I would like to add a new column based upon the values of two other columns.   

If the column "Created Date" is older than 21 days from Today,  the new column should populate with "Expired".  If the column "Created Date" is not older than 21 days,  it should return the current value in the Status column.      

 

I have tried  IF ([CreatedDate] < TODAY() -21 Then "Expired" ELSE [Status])  and IF ([CreatedDate] < TODAY() -21, "Expired", [Status])

 

Any ideas?  

 

 

Thanks in advance. 

  • Anonymous , oh, you need it in PQ. I've provided the DAX. PQ:

    if [CreatedDate] < Date.AddDays(DateTime.Date( DateTime.LocalNow()), -21) then "Expired" else [Status]

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I'd personally make a datediff calculated column with your data table, then use a Switch with case when datediff < 21 then 'Current Table'[status] else 'Expired'.

    You'll need to work out the proper syntax, but you get the idea

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

    Anonymous , what was wrong with your second try?

    cln =
    IF ( [CreatedDate] < TODAY () - 21, "Expired", [Status] )
    • Anonymous's avatar
      Anonymous
      Not applicable

      I am recieving this error message 

       

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

      Anonymous , oh, you need it in PQ. I've provided the DAX. PQ:

      if [CreatedDate] < Date.AddDays(DateTime.Date( DateTime.LocalNow()), -21) then "Expired" else [Status]