Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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?
Solved! Go to Solution.
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
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
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
9 | |
8 | |
8 |
User | Count |
---|---|
14 | |
12 | |
11 | |
11 | |
8 |