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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Aaron1
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
Anonymous
Not applicable

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

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

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>
<head>
<meta charset="UTF-8">
<title>Excel To HTML using codebeautify.org</title>
</head>
<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>

Helpful resources

Announcements
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.