cancel
Showing results for
Did you mean:
Highlighted
Frequent Visitor

## Help with YOY DAX Calculation with Filter

Hi ,

I am having trouble figuring out how to make the calculation below bring back the correct YOY values.

In my data set i data from 2015, 2016 and 2017 but want to only show data from 2017 in my visuals and tables. A key measure is YOY sales. Using the DAX below (a quick measure) it works when filters are not applied, when data is filtered to 2017 it does not return the correct answer.

I would greatly appreciate some help please?

Amount YoY =
IF(
ISFILTERED(Data[Date]),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
VAR __PREV_YEAR = CALCULATE(SUM('Data'[Amount]), DATEADD('Data'[Date].[Date], -1, YEAR))
RETURN
(SUM('Data'[Amount]) - __PREV_YEAR)
)

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team

## Re: Help with YOY DAX Calculation with Filter

Hi @Aaron1,

Maybe you can try to use below formula:

```Amount YoY =
VAR _current =
SELECTEDVALUE ( 'Data'[Date] )
VAR __PREV_YEAR =
CALCULATE (
SUM ( 'Data'[Amount] ),
FILTER (
ALL ( Data ),
[Date]
>= DATE ( YEAR ( _current ) - 1, MONTH ( _current ), DAY ( _current ) )
&& [Date] <= _current
)
)
RETURN
IF (
ISFILTERED ( Data[Date] ),
ERROR ( "Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column." ),
SUM ( 'Data'[Amount] ) - __PREV_YEAR
)
```

Notice: all function will break filter effect, if you enable it on table, current filter will be ignored, you need to manually add filter conditions to apply filter effect.

Regards,

Xiaoxin Sheng

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

For learning resources/Release notes, please visit: | |
2 REPLIES 2
Community Support Team

## Re: Help with YOY DAX Calculation with Filter

Hi @Aaron1,

Maybe you can try to use below formula:

```Amount YoY =
VAR _current =
SELECTEDVALUE ( 'Data'[Date] )
VAR __PREV_YEAR =
CALCULATE (
SUM ( 'Data'[Amount] ),
FILTER (
ALL ( Data ),
[Date]
>= DATE ( YEAR ( _current ) - 1, MONTH ( _current ), DAY ( _current ) )
&& [Date] <= _current
)
)
RETURN
IF (
ISFILTERED ( Data[Date] ),
ERROR ( "Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column." ),
SUM ( 'Data'[Amount] ) - __PREV_YEAR
)
```

Notice: all function will break filter effect, if you enable it on table, current filter will be ignored, you need to manually add filter conditions to apply filter effect.

Regards,

Xiaoxin Sheng

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

For learning resources/Release notes, please visit: | |
Frequent Visitor

## e Re: Help with YOY DAX Calculation with Filter

Hi All, I have a data set for which I need to calculate yoy change. Please help, as the data is in vertical format.

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<title>Excel To HTML using codebeautify.org</title>
<body>
<b>
<u>Sheet Name</u> :- Sheet1
</b>
<hr>
<table cellspacing=0 border=1>
<tr>
<td style=min-width:50px>Customer</td>
<td style=min-width:50px>KPI</td>
<td style=min-width:50px>unit</td>
<td style=min-width:50px>Period</td>
<td style=min-width:50px>Value</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>29029.958491000001</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>27959.362300000001</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>10029.958491000001</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>8959.3623000000007</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>34567</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>33000</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>15222</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>13655</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Customer</td>
<td style=min-width:50px>KPI</td>
<td style=min-width:50px>unit</td>
<td style=min-width:50px>Period</td>
<td style=min-width:50px>Value</td>
<td style=min-width:50px></td>
<td style=min-width:50px>yoy%</td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>29029.958491000001</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>27959.362300000001</td>
<td style=min-width:50px></td>
<td style=min-width:50px>-3.69%</td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>10029.958491000001</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Verizon</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>8959.3623000000007</td>
<td style=min-width:50px></td>
<td style=min-width:50px>-10.67%</td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>34567</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Total revenue</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>33000</td>
<td style=min-width:50px></td>
<td style=min-width:50px>-4.53%</td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2016</td>
<td style=min-width:50px>15222</td>
<td style=min-width:50px></td>
<td style=min-width:50px></td>
</tr>
<tr>
<td style=min-width:50px>Bharti</td>
<td style=min-width:50px>Capex</td>
<td style=min-width:50px>USD million</td>
<td style=min-width:50px>Q1/2017</td>
<td style=min-width:50px>13655</td>
<td style=min-width:50px></td>
<td style=min-width:50px>-10.29%</td>
</tr>
</table>
<hr>
</body>
</html>

Announcements

#### Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

#### Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 130 members 1,745 guests
Recent signins: