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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rydajo96
Helper II
Helper II

Percentage Year on Year

Hi I have the follwoing chart and I want to calculate the percentage change between the bars e.g. 1H 2019 and 2H 2019, 2H 2019 and 1H 2020. 

rydajo96_0-1665715321840.png

 

What formula should I use? Please help >< Thank you in advance 

1 ACCEPTED SOLUTION

We finally figured it out:

 

Half Yearly Change = 
    VAR CurrentPeriod = SELECTEDVALUE('Revenue by Product'[Period ID])
    VAR PreviousPeriod = IF(CurrentPeriod > 1, CurrentPeriod - 1, 1)
    
    VAR CY = [Revenue]
    VAR PY = CALCULATE([Revenue], FILTER(ALLSELECTED('Revenue by Product'), 'Revenue by Product'[Period ID]=PreviousPeriod))
    VAR Result = DIVIDE (CY,PY) 
    RETURN (IF(NOT(ISBLANK(Result)) && ISFILTERED('Revenue by Product'[Period]), Result-1))

View solution in original post

48 REPLIES 48
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lukiz84
Memorable Member
Memorable Member

You sure its YoY? 😉 Looks like HY to HY 🙂 See:

 

Change 6M % =
   VAR Current = [yourMeasure]
   VAR Previous = 
      CALCULATE(
          [yourMeasure],
          DATEADD(yourDateTable[Date], -6, MONTH)
      )
 
   RETURN DIVIDE(Current, Previous)

 

Hello

 

Thank for the formula, unforuntately I didnt get the output,. It's returning all 100% but with the following line and is not in the right direction:

rydajo96_0-1665717349246.png

This is the formula I used:

 Half Yearly Change =

VAR CY = [Revenue]

VAR PY = CALCULATE([Revenue], DATEADD('Revenue by Product'[Year/Month].[Date],-6,MONTH) )

RETURN DIVIDE (CY,PY) 

 
The formula for revenue is: 

 

Revenue = -sum('Revenue by Product'[Sum_Amount]) 

 

 

This is the data I have (unable to share the notebook due to NDA):

Acct NameProduct CatYear/MonthCustomerSum AmountPeriodPeriod ID
ABCXYZFriday, 1 Mar 20191232991H 20191

 

Is there a way I can make use of the period ID?

Do you have a date table in place?

Can you put the Periods in a matrix and add the Half Year Change so i can see the values?

There is no separate dates table, the dates are in the column "Year/Month" in the previous reply. This is the matrix:

rydajo96_0-1665718142129.png

 

Oh ok, and Period ID (not Period) has which values?

 

Period ID is from 1 to 7 

Period is 1H2019...1H2022

Ok, in general i would suggest you implement a date table to be able to use the time intelligence funtions like DATEADD... it's not possible in your scenario. Anyway this should work:

 

Change 6M % =
   VAR CurrentPeriod = SELECTEDVALUE(table[Period ID])
   VAR PreviousPeriod = IF(CurrentPeriod > 1, CurrentPeriod - 1, 1)

   VAR Current = [Revenue]
   VAR Previous = 
      CALCULATE(
          [Revenue],
          table[Period ID] = PreviousPeriod
      )
 
   RETURN DIVIDE(Current, Previous)

I am trying to tweak this formula as it is returning a similar output but not the exact output 

 

Revenue % difference from Revenue = 
VAR __BASELINE_VALUE = 	CALCULATE(
		[Revenue],
		'Revenue by Product'[Period] IN {"1H 2020"},
		ALL('Revenue by Product'[Period ID])
	)
VAR __VALUE_TO_COMPARE = CALCULATE([Revenue], DATEADD('Revenue by Product'[Year/Month].[Date],-6,MONTH))
RETURN
	IF(
		NOT ISBLANK(__VALUE_TO_COMPARE),
		DIVIDE(__VALUE_TO_COMPARE - __BASELINE_VALUE, __BASELINE_VALUE)
	)

 

However, it is using "1H 2020" as the base. Is there anyway I can tweak the formula to make it change from one period to another?

no need, just use the code i provided above (the new one). you can't use dateadd because you don't have a date table

I got this error

rydajo96_0-1665720182590.png

 

This is the formula I used per your reply

Half Yearly Change = 
    VAR CurrentPeriod = SELECTEDVALUE('Revenue by Product'[Period ID])
    VAR PreviousPeriod = IF(CurrentPeriod > 1, CurrentPeriod - 1, 1)
    
    VAR CY = [Revenue]
    VAR PY = CALCULATE([Revenue], 'Revenue by Product'[Period ID]=PreviousPeriod)
RETURN DIVIDE (CY,PY) 

What does "See details" say? 🙂

It says this

rydajo96_1-1665720371231.png

 

Ok then your Period ID is not of type "Integer" (or Whole number), please fix it (maybe in PowerQuery). Then it should work.

I have changed but it seems it only return for 1H 2019

rydajo96_0-1665720701849.png

 

That doesn't make sense to me, can you show the matrix again?

This is the matrix for the calculated formula you gave

rydajo96_0-1665720975957.png

Matrix for period

rydajo96_1-1665720986318.png

 

Ah sorry,

 

 

Half Yearly Change = 
    VAR CurrentPeriod = SELECTEDVALUE('Revenue by Product'[Period ID])
    VAR PreviousPeriod = IF(CurrentPeriod > 1, CurrentPeriod - 1, 1)
    
    VAR CY = [Revenue]
    VAR PY = CALCULATE([Revenue], 'Revenue by Product'[Period ID]=PreviousPeriod)
    VAR Result = DIVIDE (CY,PY) 
    RETURN (IF(NOT(ISBLANK(Result)), Result-1)

 

The -1 in VAR PY is outisde the bracket?

i edited the post, it should not be in the VAR PY line...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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