Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
So I've been using the following DAX expression for a while now and today was the first day it caused me problems.
Week of Report = DATE(YEAR([Date of Report]), MONTH([Date of Report]), DAY([Date of Report]) - WEEKDAY([Date of Report], 2) + 1)
The error I get thrown is:
MdxScript(Model) (62, 40) Calculation error in measure 'Measure Table'[Week of Report]: An > >argument of function 'DATE' has the wrong data type or the result is too large or too small.
Now after some thought I realized maybe this is a problem with going backwards across a month that I've never noticed. The [Date of Report] was 11/1/2022 and so I figured maybe going backwards to 10/31/22 was causing an issue.
Just for testing purposes I removed the + 1 at the end. The code worked!! It correctly output 10/30/22. So why was that little pesky + 1 causing an issue? I decided to try other variations of DAX that should produce the same output. (I actually ended up adopting one of the alternatives but this question still bugged me enough to post it here)
Code variations that correctly output 10/31/22:
Week of Report = DATE(YEAR([Date of Report]), MONTH([Date of Report]), DAY([Date of Report])) - WEEKDAY([Date of Report], 2) + 1
Week of Report = [Date of Report] - WEEKDAY([Date of Report], 2) + 1
So why in the world does the first code variation not work?!? Is this a Power BI bug or is there something else at play?
Solved! Go to Solution.
Hi @TallPolishAdam ,
I think the final two measures should be correct.
In your first code, you add "- WEEKDAY([Date of Report], 2) + 1" in Date() function. Power BI will check whether year/month/day parts all correct, then return date value. So if day part return Negative numbers, Power BI will return error.
Week of Report =
DATE ( YEAR ( [Date of Report] ), MONTH ( [Date of Report] ), DAY ( [Date of Report] ) - WEEKDAY ( [Date of Report], 2 ) + 1 )
The final two measures, both add "- WEEKDAY([Date of Report], 2) + 1" outof date, so Power BI will do calculation on [Date of Report] and think "- WEEKDAY([Date of Report], 2) + 1" as days.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Yes, that is correct. DATE() would likely end up being 2022/11/0 with the +1 in there which fails. But when I remove the +1 the function correctly outputs 2022/10/30 instead of the expected error that would be associated with 2022/11/-1. I feel like either both should work or neither.
Hi @TallPolishAdam ,
I think the final two measures should be correct.
In your first code, you add "- WEEKDAY([Date of Report], 2) + 1" in Date() function. Power BI will check whether year/month/day parts all correct, then return date value. So if day part return Negative numbers, Power BI will return error.
Week of Report =
DATE ( YEAR ( [Date of Report] ), MONTH ( [Date of Report] ), DAY ( [Date of Report] ) - WEEKDAY ( [Date of Report], 2 ) + 1 )
The final two measures, both add "- WEEKDAY([Date of Report], 2) + 1" outof date, so Power BI will do calculation on [Date of Report] and think "- WEEKDAY([Date of Report], 2) + 1" as days.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Just looking at the code, my guess is, because you are adding 1 to a number then subtracting that you are getting some results like 2022/10/-1
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
118 | |
79 | |
47 | |
45 | |
32 |
User | Count |
---|---|
172 | |
90 | |
66 | |
46 | |
45 |