Forum Discussion

TallPolishAdam's avatar
TallPolishAdam
Frequent Visitor
3 years ago
Solved

Adding a +1 inside Date function results in an error but when adding +1 outside works fine, why?

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...
  • Anonymous's avatar
    Anonymous
    3 years ago

    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.