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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jdb2313
Regular Visitor

An argument of function date error

jdb2313_0-1658342458556.png

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 missing?

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

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.

vcazhengmsft_0-1658717848614.png

 

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

View solution in original post

2 REPLIES 2
v-cazheng-msft
Community Support
Community Support

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.

vcazhengmsft_0-1658717848614.png

 

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

HotChilli
Super User
Super User

As general debugging advice, simplify the IF statement to something basic when this sort of thing occurs - really basic to make it work syntactically (keep a copy elsewhere so you don't throw away the code) - and then build it up piece by piece

In terms of readability, capitalise the DAX keywords.

---

Are you creating a column or a measure?  If this is a column you should not be using a measure in the formula (and it looks like MaxDate is a measure)

Is

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.