Forum Discussion

jdb2313's avatar
jdb2313
Regular Visitor
4 years ago
Solved

An argument of function date error

I'm getting an error message that the date function has the wrong data type. I've checked all the fields in the calculation. They are all date types. I'm fairly new to Dax. What could I be miss...
  • v-cazheng-msft's avatar
    4 years ago

    Hi jdb2313,

     

    May I know whether you still have problem on it? If it still exists, please take these official documents as reference to check your arguments.

    DATE function (DAX) - DAX | Microsoft Docs

    YEAR function (DAX) - DAX | Microsoft Docs

    MONTH function (DAX) - DAX | Microsoft Docs

    DAY function (DAX) - DAX | Microsoft Docs

     

    And check your fields’ data types in its Formatting section to make sure they are qualified.

     

    For it’s a long DAX formula. Here is a website that can help you format your DAX formula for better reading. DAX Formatter by SQLBI

     

    And for there are many duplicated code segment in your formula, I would recommend you using variable in it, which will help you simplify the formula and accelerate the calculation.

    Use variables to improve your DAX formulas - DAX | Microsoft Docs

     

    Then, the dax should look like this.

    Rolling4QtrMin =
    VAR bool =
        DAY ( [MaxDate] ) = 29
            && MONTH ( [MaxDate] ) = 2
    VAR trueVal =
        DATE ( YEAR ( [MaxDate] ) - 1, 2, 28 ) + 1
    VAR falseVal =
        DATE ( YEAR ( [maxDate] ) - 1, MONTH ( [MaxDate] ), DAY ( [MaxDate] ) ) + 1
    RETURN
        IF (
            DAY ( IF ( bool, trueVal, falseVal ) ) = 29
                && MONTH ( IF ( bool, trueVal, falseVal ) ) = 2,
            DATE ( YEAR ( [MaxDate] ) - 1, 2, 1 ),
            IF ( bool, trueVal, falseVal )
        )

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

     

    Best Regards,

    Community Support Team _ Caiyun