I need to compute a year-over-year YoY growth rate but only for months where I have data in both years how do I do this

0 votes

I need to compute a year-over-year (YoY) growth rate but only for months where I have data in both years—how do I do this?
I want to calculate the year-over-year (YoY) growth rate in Power BI, but I only want to include months where data is available for both the current and previous year. What is the best approach using DAX functions like CALCULATE, SAMEPERIODLASTYEAR, or INTERSECT to ensure accurate comparisons?

Mar 10 in Power BI by Evanjalin
• 25,690 points
61 views

1 answer to this question.

0 votes

Calculating Year-over-Year (YoY) growth only for those months for which there are entries in both years, you would use DAX like this:

DAX Measure for YoY Growth with Matching Months

YoY Growth % = 
VAR CurrentYearSales = SUM( 'Sales'[TotalSales] )
VAR PreviousYearSales = 
    CALCULATE( 
        SUM( 'Sales'[TotalSales] ), 
        SAMEPERIODLASTYEAR( 'Date'[Date] ) 
    )

VAR MonthsWithData = 
    INTERSECT( 
        VALUES( 'Date'[MonthYear] ), 
        CALCULATETABLE( VALUES( 'Date'[MonthYear] ), SAMEPERIODLASTYEAR( 'Date'[Date] ) ) 
    )

VAR AdjustedCurrentSales = 
    CALCULATE( CurrentYearSales, 'Date'[MonthYear] IN MonthsWithData )

VAR AdjustedPreviousSales = 
    CALCULATE( PreviousYearSales, 'Date'[MonthYear] IN MonthsWithData )

RETURN 
    IF( AdjustedPreviousSales > 0, 
        DIVIDE( AdjustedCurrentSales - AdjustedPreviousSales, AdjustedPreviousSales ), 
        BLANK()
    )

The rationale for the process is:

Compute the Sales for both years.

Current Year Sales = Total sales for the current period.

Previous Year Sales = Sales for the same period in the last year's calculations using the function SAME-PERIOD-LAST-YEAR( ).

Find Common Months with Data

The function INTERSECT( ) extracts only those months that exist in both the current and previous years.

Filter Sales for Matching Months

Adjusted Current Sales and Adjusted Previous Sales ensure that only months with data in both years are considered.

Calculate YoY growth

The DIVIDE( ) function is for safe division, which means it can return BLANK if a valid comparison cannot be performed.

answered Mar 10 by anonymous
• 25,690 points

Related Questions In Power BI

+1 vote
1 answer
0 votes
1 answer

How do I configure a read-only user for PostgreSQL in Power BI to maintain security?

To configure a read-only user for PostgreSQL ...READ MORE

answered Feb 28 in Power BI by anonymous
• 25,690 points
70 views
0 votes
1 answer

I need to calculate a running total but reset it at the start of each new quarter—how can I achieve this in DAX?

To calculate a running total that resets ...READ MORE

answered Mar 7 in Power BI by anonymous
• 25,690 points
86 views
0 votes
1 answer

I have a web API with basic authorisation and username and password. How do i connect to it in Power BI?

Hey, @There, I found your query is quite ...READ MORE

answered Oct 29, 2020 in Power BI by Gitika
• 65,770 points
4,014 views
+2 votes
0 answers

Assume referential integrity

1) What is Assume referential integrity? what ...READ MORE

Aug 19, 2019 in Power BI by vnk
1,963 views
+2 votes
1 answer

If Condition

DAX - I assume [Claim_line].[Allowed_Amount_B6] is one ...READ MORE

answered Aug 20, 2019 in Power BI by anonymous
• 33,050 points
1,773 views
+2 votes
1 answer

How to export data to CSV from power bi embedded url ?

Hi Arathi, You can open Visuals from embedded ...READ MORE

answered Aug 23, 2019 in Power BI by anonymous
• 33,050 points
6,830 views
+1 vote
1 answer

Power Bi to Machine Learning Model

Hello @vnk! Power BI only supports Azure Machine ...READ MORE

answered Dec 3, 2019 in Power BI by Priyanka
1,356 views
0 votes
1 answer
0 votes
1 answer

I need to show a trendline for a moving average but only for selected date ranges—how can I do this?

To do a Moving Average Trendline that ...READ MORE

answered Mar 19 in Power BI by anonymous
• 25,690 points
53 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP