cancel
Showing results for
Did you mean: Frequent Visitor

## DAX for YoY rate calculation

Hi everybody,

I currently have a table where I want to see the YoY growth rate for different locations. The date I have been using is not continuous or has an specific pattern, so when I tried doing YoY calculation I always received the following error: "Function DATEADD expects a contiguous selection when the date column is not unique, has gaps...". Is there perhaps a way to calculate YoY rate for no continous dates??

The table I'm working with looks like this, where Nod is a location and the amount per year describes the sales: What I would like to have is the percent difference table calculation that you can find in Tableau: The measures I used were:

``````YOY diff =
VAR previousDateWithPrice =
CALCULATE (
MAX ( 'capa'[Dates]),
FILTER ( ALL ( 'capa' ), 'capa'[Sales] > 0 && 'capa'[Dates] < MAX ( 'capa'[Dates] ) )
)
VAR previousPrice =
CALCULATE (
SUM ('capa'[Dates] ),
FILTER ( ALL ( 'capa' ), 'capa'[Dates] = previousDateWithPrice )
)
RETURN
DIVIDE ( SUM ( 'capa'[Sales] ) - previousPrice, previousPrice )``````

1 ACCEPTED SOLUTION  Community Support

According to your description, if you just want to show the annual growth rate, here's my solution.

This is my sample data. I modify your formula like this:

``````YOY diff =
VAR previousDateWithPrice =
CALCULATE (
MAX ( 'capa'[Dates].[Year] ),
FILTER (
ALL ( 'capa' ),
'capa'[Sales] > 0
&& 'capa'[Dates].[Year] < MAX ( 'capa'[Dates].[Year] )
)
)
VAR previousPrice =
CALCULATE (
SUM ( 'capa'[Sales] ),
FILTER (
ALL ( 'capa' ),
'capa'[Nod] = MAX ( 'capa'[Nod] )
&& 'capa'[Dates].[Year] = previousDateWithPrice
)
)
RETURN
DIVIDE ( SUM ( 'capa'[Sales] ) - previousPrice, previousPrice )
``````

Get the correct result. I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  Community Support

According to your description, if you just want to show the annual growth rate, here's my solution.

This is my sample data. I modify your formula like this:

``````YOY diff =
VAR previousDateWithPrice =
CALCULATE (
MAX ( 'capa'[Dates].[Year] ),
FILTER (
ALL ( 'capa' ),
'capa'[Sales] > 0
&& 'capa'[Dates].[Year] < MAX ( 'capa'[Dates].[Year] )
)
)
VAR previousPrice =
CALCULATE (
SUM ( 'capa'[Sales] ),
FILTER (
ALL ( 'capa' ),
'capa'[Nod] = MAX ( 'capa'[Nod] )
&& 'capa'[Dates].[Year] = previousDateWithPrice
)
)
RETURN
DIVIDE ( SUM ( 'capa'[Sales] ) - previousPrice, previousPrice )
``````

Get the correct result. I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Announcements The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform. #### Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison! #### The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022. Top Solution Authors
Top Kudoed Authors
Users online (2,166)