Forum Discussion

PatriceGREN's avatar
PatriceGREN
Regular Visitor
6 years ago
Solved

Using Dateadd

Hi, 

I can t use the DATEADD function correctly.

DATEADD(HISTORIQUE[DateFinPeriodeEssai1],-nbjprevenance,DAY)

-nbjprevenance = variable 

if I put 0 in place of the variable, I get the right dates. But as soon as I want to add or subtract, nothing goes, sometimes I have the right answer, sometimes nothing.

Thank you for your help

  • PatriceGREN's avatar
    PatriceGREN
    6 years ago

    Hi,

    After many tests, I tried this syntax:

    HISTORIQUE[DateFinPeriodeEssai1] - nbjprevenance

    and it works.

     

     

6 Replies

  • PatriceGRENcan you provide details on how you are calculating nbjprevenance variable? Also do you have date dimension in your model on which you are performing this DateADD function?

    • PatriceGREN's avatar
      PatriceGREN
      Regular Visitor

      Hi, 

      datePrevenancePeriodeEssai1 =

      var nbj = HISTORIQUE[NombreJourDebutContrataDateJour]

      var nbjprevenance =

      switch(TRUE(); -- donne le nombre de jours de prévenance à respecter

      nbj <8 ; 1;

      and(nbj > 8 ; nbj <= 30);2;

      and(nbj >30 ; nbj <= 90);15;30 )

      return

      DATEADD(HISTORIQUE[DateFinPeriodeEssai1];-nbjprevenance;DAY)

       

      for the "Date Dimension", I'll look. This is a model that is available to me, I don't know yet everything in it.

      • PatriceGREN's avatar
        PatriceGREN
        Regular Visitor

        Hi,

        After many tests, I tried this syntax:

        HISTORIQUE[DateFinPeriodeEssai1] - nbjprevenance

        and it works.

         

         

  • In case you plan to use a slicer, you can have a measure. Here "Add to date" is a slicer

     

    Date from slicer = 
    Var date1='Add To Date'[Add To Date Value]
    
    return
    CALCULATE(maxx(Sales,DATEADD(Sales[Order_Date],date1,DAY)))

     

     

    You want to add static value once as column 

     

    Date from slicer col = 
    Var date1=1
    
    return
    DATEADD(Sales[Order_Date],-1*date1,DAY)

     

    • PatriceGREN's avatar
      PatriceGREN
      Regular Visitor

      Hi, I understand your solution, but it doesn't work for all my data