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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
sentsara
Helper II
Helper II

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 @YOY

select 'SC','Mol',2017,2019,3.0 union all
select 'SC','Wel',2017,2019,3.0 union all
select 'SC','BCB',2017,2019,3.5 union all
select 'SC','cen',2017,2019,3.5 union all
select 'SC','amer',2017,2019,4.0 union all
select 'SC','Mol',2016,2018,3.0 union all
select 'SC','Wel',2016,2018,2.5 union all
select 'SC','BCB',2016,2018,3.0 union all
select 'SC','cen',2016,2018,3.0 union all
select 'SC','amer',2016,2018,3.5 union all
select 'SC','Mol',2015,2017,3.0 union all
select 'SC','Wel',2015,2017,3.0 union all
select 'SC','BCB',2015,2017,3.0 union all
select 'SC','cen',2015,2017,3.0 union all
select 'SC','amer',2015,2017,4.0

select * from @YOY

 

Expected output: 

YOY% =  Rating / PreviousYearRating

PlanIDCompetitorsDateofserviceRatingYearRatingPreviousYearRatingPreviousYearRatingYOY%
SCMol20172019320183        
SCWel20172019320182.5        
SCBCB201720193.520183        
SCcen201720193.520183        
SCamer20172019420183.5        
SCMol20162018320173        
SCWel201620182.520173        
SCBCB20162018320173        
SCcen20162018320173        
SCamer201620183.520174        
SCMol20152017320160 
SCWel20152017320160 
SCBCB20152017320160 
SCcen20152017320160 
SCamer20152017420160 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

-- 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

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Mate, what's the definition of YOY%? The very first line in your data set states that YOY% is 1.000 but I can see that the rating goes from 3 to 3. How the heck then is it possible that the relative increase is 1?

 

The other issue is... What is it that you want? Is it a measure? A column? What's the input data? Mate, please do yourself a favor and be more descriptive.

 

Thanks. 

 

Best

Darek

Updated my content.

 

i need to bring two columns value

PreviousYearRating for the same competitors what is the rating achieved and find the Year over Year (%) changes

 

Anonymous
Not applicable

-- 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

Thank you so much darlove. its working 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.