Forum Discussion

RonaldvdH's avatar
RonaldvdH
Icon for Post Patron rankPost Patron
6 years ago
Solved

Formula to subtract days based on a date column

Ive such a simple question but im unable to fix it.

 

I need to plan an activity base upon another activity and therefore i need to subtract 14 days from a date column but the result returns a date in the year 1899

 

The formula is simple 

Sisu gepland = Adressen[civiel begin]-14
 
But the result is 50% correct because the date is good but the year wrong and actually i want to subtract 14 working days
  • Hi, it will depend in where you solve this. You have to create a new column. If you want to solve it in edit queries check "AddDays" function. If you want to solve this with DAX check "DATEADD" function. In order to make it work the column has to be date type. 

     

    Hope this helps,

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • ibarrau ive corrected the problem and the right formula should be 

     

    Sisu gepland = dateadd(Adressen[civiel begin].[Date];-14;DAY)
     
    However do you know how to make sure it subtracts workingdays instead of just days because in this formula the date could be a saturday or sunday.
    I have a 'date' table with a column in it to check if its a weekday

4 Replies

  • Hi, it will depend in where you solve this. You have to create a new column. If you want to solve it in edit queries check "AddDays" function. If you want to solve this with DAX check "DATEADD" function. In order to make it work the column has to be date type. 

     

    Hope this helps,

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • RonaldvdH's avatar
      RonaldvdH
      Icon for Post Patron rankPost Patron

      ibarrau ive corrected the problem and the right formula should be 

       

      Sisu gepland = dateadd(Adressen[civiel begin].[Date];-14;DAY)
       
      However do you know how to make sure it subtracts workingdays instead of just days because in this formula the date could be a saturday or sunday.
      I have a 'date' table with a column in it to check if its a weekday
      • ibarrau's avatar
        ibarrau
        Icon for Super User rankSuper User

        Power bi by default won't help you with working days. This is something you have to create, do some data modeling first.

        Check this post talking about them: https://www.sqlbi.com/articles/counting-working-days-in-dax/

        Right now your formula just substract days in general.

         

        Regards,

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.