Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Y-Hernandez99P
Frequent Visitor

HELP, Why doesn't DATEADD() work with a column that is equal to Today() or Now()?

Good morning, I hope you're all right.

I have a little doubt and it is: Why when I use THE DATEADD() functions when a column or variable is declared with the NOW() or Today functions?

I have to make a report which brings me data of some orders from the organization from the day before 6pm until the current day at 6pm... From the BI slicers I saw that I couldn't do the specific filters as I wanted, so I was doing a support column in DAX where if there is data with current date and its time is less than or equal to 18 (6pm) then put a 1, if you put 0. In case if the day is not equal to the current day, check if the day of the row is equal to the day of the previous date, then check if the time of the row is greater than or equal to 18.... Seeing that I didn't have the expected results, with a check column, I set the current date, and in the other the DATEADD function which it pulls out the previous day, and when checking the last column was empty.
Do you have any choice of how to make these validations?

ValidarFecha = 
var diafechaCol = DAY([FechaDoc])
var diafechaAct = DAY(TODAY())
var fechadiaAnt = DATEADD(IV_PEDIDOS8D[APOYO_fechaActual];-1;DAY)
var diafechaAnt = DAY(fechadiaAnt)
var horafechaAct = [HoraCreacion]
Return
IF(diafechaAct = diafechaCol;
    IF(horafechaAct <= 18; 1;0)
        ;IF((diafechaAct = diafechaAnt);
            IF(horafechaAct >= 18;1;0)
        ;0)
)

dau.png

Here the column on the left is equal to NOW() (same as I did with today and it still doesn't work), and next to it is the column that is equal to DATEADD(IV_PEDIDOS8D[APOYO_fechaActual];-1;day) and goes blank.

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Y-Hernandez99P ,

Time-intelligence-functions like DateAdd() needs a separate continuous date table. In this issue, you can create a column like this:

Column =
VAR _lastday =
    DAY ( TODAY () - 1 )
VAR _today =
    DAY ( TODAY () )
VAR _day =
    DAY ( 'Table'[date] )
VAR _hour =
    HOUR ( 'Table'[date] )
RETURN
    IF (
         ( _day = _today
            && _hour <= 18 )
            || ( _day = _lastday
            && _hour >= 18 ),
        1,
        0
    )

re.png

 

Best Regards,
Yingjie Li

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

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @Y-Hernandez99P ,

Time-intelligence-functions like DateAdd() needs a separate continuous date table. In this issue, you can create a column like this:

Column =
VAR _lastday =
    DAY ( TODAY () - 1 )
VAR _today =
    DAY ( TODAY () )
VAR _day =
    DAY ( 'Table'[date] )
VAR _hour =
    HOUR ( 'Table'[date] )
RETURN
    IF (
         ( _day = _today
            && _hour <= 18 )
            || ( _day = _lastday
            && _hour >= 18 ),
        1,
        0
    )

re.png

 

Best Regards,
Yingjie Li

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

amitchandak
Super User
Super User

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.