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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
nmcge
Frequent Visitor

Nested IF/AND statements in a calculated column

I'm having some trouble with nested IF statements in a calcualted column on my date table.  Essentially, I need a fiscal year that starts at the beginning of February and runs until 31st January, maintaining 52 weeks - the result of which leaves an unusual number of days in the final week of of one year and the beginning week of the next.
 
For the life of me, I can't see why the following formula is not calculating correctly.  If the date is 8th January, it should surely provide the value of _Date[Z_FW] (in this case, 52) as the first condition is true (year = 2023, date is less than 31st Jan).  Instead, it is applying the condition of the second, untrue statement giving the value -3 (_Date[Week of Year] -5).
 
FinWeek =
     IF(
        AND(
            _Date[FYr] = 2023,
            _Date[Date] <= DATE(31,01,2023)), 
        _Date[Z_FW], 
        IF (
            AND(
                _Date[FYr] = 2023
                , _Date[Date] >= DATE(01,02,2023)), 
            _Date[Week of Year] -5,
            IF(
               AND(
                    _date[date] >= DATE(01,02,2022),
                    _date[date] <= DATE(06,02,2022)),
                    1,
               _Date[Z_FW]
            )
        )
    )
 
Can anyone help me debug this?  I'm at a loss, and must be missing something fundamental...
1 ACCEPTED SOLUTION
Anil_kapkoti
New Member

It Seems that you have an issue in the date values,
Try This
FinWeek =
IF(
AND(
_Date[FYr] = 2023,
_Date[Date] <= DATE(2023, 01, 31)
),
_Date[Z_FW],
IF (
AND(
_Date[FYr] = 2023,
_Date[Date] >= DATE(2023, 02, 01)
),
_Date[Week of Year] - 5,
IF(
AND(
_Date[Date] >= DATE(2022, 02, 01),
_Date[Date] <= DATE(2022, 02, 06)
),
1,
_Date[Z_FW]
)
)
)

View solution in original post

2 REPLIES 2
Anil_kapkoti
New Member

It Seems that you have an issue in the date values,
Try This
FinWeek =
IF(
AND(
_Date[FYr] = 2023,
_Date[Date] <= DATE(2023, 01, 31)
),
_Date[Z_FW],
IF (
AND(
_Date[FYr] = 2023,
_Date[Date] >= DATE(2023, 02, 01)
),
_Date[Week of Year] - 5,
IF(
AND(
_Date[Date] >= DATE(2022, 02, 01),
_Date[Date] <= DATE(2022, 02, 06)
),
1,
_Date[Z_FW]
)
)
)

Haha, can't believe I couldn't see that.  I must have had a tough day yesterday.

 

Really appreciate it!  Thank you.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.