Forum Discussion

mcor13's avatar
mcor13
Regular Visitor
1 year ago
Solved

Calculate Financial Period End Date

Hi I'm tring to add a calculated column to a date table to define the financial period for a year that starts 1st April.   Period 1 ends on the 4th Saturday of April then periods end using the fol...
  • Gabry's avatar
    1 year ago

    Hey buddy,

    could you try this?

    Period = 
    VAR ThisDate      = 'Date'[Date]
    
    VAR FY            = YEAR(ThisDate) - IF(MONTH(ThisDate) < 4, 1, 0)
    
    
    VAR StartOfFY     = DATE(FY, 4, 1)
    
    
    VAR FirstSaturday =
        StartOfFY +
        MOD(6 - WEEKDAY(StartOfFY, 2), 7)
    
    
    VAR FourthSaturday = FirstSaturday + 21
    
    
    VAR BoundP1  = FourthSaturday
    VAR BoundP2  = BoundP1  + 28
    VAR BoundP3  = BoundP2  + 35
    VAR BoundP4  = BoundP3  + 28
    VAR BoundP5  = BoundP4  + 28
    VAR BoundP6  = BoundP5  + 35
    VAR BoundP7  = BoundP6  + 28
    VAR BoundP8  = BoundP7  + 28
    VAR BoundP9  = BoundP8  + 35
    VAR BoundP10 = BoundP9  + 28
    VAR BoundP11 = BoundP10 + 28
    
    VAR BoundP12 = DATE(FY + 1, 3, 31)
    
    
    RETURN
        SWITCH(
            TRUE(),
            ThisDate <= BoundP1,  1,
            ThisDate <= BoundP2,  2,
            ThisDate <= BoundP3,  3,
            ThisDate <= BoundP4,  4,
            ThisDate <= BoundP5,  5,
            ThisDate <= BoundP6,  6,
            ThisDate <= BoundP7,  7,
            ThisDate <= BoundP8,  8,
            ThisDate <= BoundP9,  9,
            ThisDate <= BoundP10, 10,
            ThisDate <= BoundP11, 11,
          
            12
        )