Forum Discussion

sentsara's avatar
sentsara
Helper II
7 years ago
Solved

YOY Calculation

Hi Team,   Need help on YOY [Year Over Year) % Changes Declare @YOY table ( PlanID Varchar(10), Competitors varchar (100), Dateofservice int, RatingYear int, Rating float ) insert into @YO...
  • Anonymous's avatar
    Anonymous
    7 years ago
    -- Assumptions:
    -- T is the table
    -- RatingYear is integer
    
    -- Questions:
    -- What's the use of PlanID if in the
    -- sample data set it's all the same?
    
    -- calculated column
    [PreviousYearRating] =
    var __currentYear = T[RatingYear]
    var __prevYear = __currentYear - 1
    var __currentCompetitor = T[Competitors]
    -- If this calculation is slow, then one has
    -- to use an alternative that will not use
    -- CALCULATE but only FILTER on its own. var __prevYearRating =
        CALCULATE(
            VALUES( T[Rating] ),
            T[Competitors] = __currentCompetitor,
            T[RatingYear] = __prevYear,
            ALL ( T )
        ) return __prevYearRating -- calculated column -- Please do not multiply the output by 100. -- Use formatting to format the number correctly as percentage. [YOY%] = var __currentRating = T[Rating] var __prevYearRating = T[PreviousYearRating] var __yoy = DIVIDE( __currentRating, __prevYearRating ) return __yoy

    Best

    Darek