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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
v-shex-msft
Community Support
Community Support

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
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

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
If this post helps, please consider accept as solution to help other members find it more quickly.

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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