Forum Discussion

Devtr's avatar
Devtr
Helper III
3 years ago
Solved

An argument or function DATE has wrong data type will not resolve

I have two tables with hotel reservations. The first is for future reservations and the other is for past ones from last year.   FutureReservations arrival_date departure_date total_nights r...
  • Greg_Deckler's avatar
    Greg_Deckler
    3 years ago

    Devtr I see the issue, sometimes _First_Arr_Date is BLANK.

    Try this:

    LY_Past_Res_Rooms = 
    var _First_Arr_Date = FIRSTDATE('FutureReservations'[arrival_date])
    return
    if(_First_Arr_Date = BLANK(), BLANK(),
            var _LY_First_Arr_Date = DATE(YEAR(_First_Arr_Date)-1,MONTH(_First_Arr_Date),DAY(_First_Arr_Date))
    
            var _Last_Dep_Date = LASTDATE('FutureReservations'[departure_date])
            var _LY_Last_Arr_Date = DATE(YEAR(_Last_Dep_Date)-1,MONTH(_Last_Dep_Date),DAY(_Last_Dep_Date))
            var _Result = CALCULATE(COUNT('Past_Reservations'[rate_cat]),
                    FILTER(ALL('Past_Reservations'[arrival_date]),
                            'Past_Reservations'[arrival_date]>=DATEVALUE(_LY_First_Arr_Date)
                            &&
                            'Past_Reservations'[arrival_date]<DATEVALUE(_LY_Last_Arr_Date)
                            &&
                            'Past_Reservations'[arrival_date]<>BLANK()))
            return
            _Result
    )