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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rohit403
Helper I
Helper I

yoy calculation in DAX with date table and vertical format

Hi All,

 

I need your advise and help in calculating YOY (year on year) percentage change. The data as well as the result required is in the below format. I have a date table too, whose screenshot I have also provided. I must mention that I was able to do this by inserting a column in the Power BI table view. However, as my project is on a server, I cant edit the table and can just create a new measure. However I am struggling with the DAX formula for the same. Please help:

 

CustomerKPIunitPeriodValue
VerizonTotal revenueUSD millionQ1/201629029.95849
VerizonTotal revenueUSD millionQ1/201727959.3623
VerizonCapexUSD millionQ1/201610029.95849
VerizonCapexUSD millionQ1/20178959.3623
BhartiTotal revenueUSD millionQ1/201634567
BhartiTotal revenueUSD millionQ1/201733000
BhartiCapexUSD millionQ1/201615222
BhartiCapexUSD millionQ1/201713655

 

 

 

CustomerKPIunitPeriodValue yoy%
VerizonTotal revenueUSD millionQ1/201629029.95849  
VerizonTotal revenueUSD millionQ1/201727959.3623 -3.7%
VerizonCapexUSD millionQ1/201610029.95849  
VerizonCapexUSD millionQ1/20178959.3623 -10.7%
BhartiTotal revenueUSD millionQ1/201634567  
BhartiTotal revenueUSD millionQ1/201733000 -4.5%
BhartiCapexUSD millionQ1/201615222  
BhartiCapexUSD millionQ1/201713655 -10.3%

 

Date.JPG

Thanks

 

 

1 ACCEPTED SOLUTION

Hi Rohit,

 

I created a new version of the measure that works more generally. Please give it a try.

Measure 2 =
VAR lastPeriod =
    CALCULATE (
        MAX ( test01[Period] ),
        FILTER (
            ALL ( test01[Period] ),
            DATEVALUE ( REPLACE ( test01[Period], 1, 1, 0 ) )
                < DATEVALUE ( REPLACE ( MIN ( test01[Period] ), 1, 1, 0 ) )
        )
    )
VAR lastValue =
    CALCULATE (
        MAX ( test01[Value] ),
        FILTER ( ALL ( test01[Period] ), test01[Period] = lastPeriod )
    )
RETURN
    DIVIDE ( MIN ( test01[Value] ) - lastValue, lastValue, BLANK () )

yoy-calculation-in-DAX-with-data-in-veritical-format2

 

 

Best Regards,

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

View solution in original post

8 REPLIES 8
v-jiascu-msft
Employee
Employee

Hi Rohit,

 

How about a calculated column? Please refer to the formula and snapshot below.

Column =
VAR customer = [Customer]
VAR kpi_ = [KPI]
VAR currentValue = [Value]
VAR currentIndex = [Index]
VAR lastPeriodValue =
    CALCULATE (
        SUM ( Table1[Value] ),
        FILTER (
            Table1,
            Table1[Index] = currentIndex - 1
                && Table1[Customer] = customer
                && Table1[KPI] = kpi_
        )
    )
RETURN
    DIVIDE ( currentValue - lastPeriodValue, lastPeriodValue, BLANK () )

yoy-calculation-in-DAX-with-data-in-veritical-format

 

Best Regards,

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

Hi  ,

 

Thanks for your quick response.

 

However I have a challenge here, I am doing these calculations on an online database where I can't edit the tables. I have to do the calculations in the report only using measures.

 

So can we do that without modifying the tables.

 

Once again thanks so much for your help and time.

 

Thanks,

Rohit

Hi Rohit,

 

I created a new version of the measure that works more generally. Please give it a try.

Measure 2 =
VAR lastPeriod =
    CALCULATE (
        MAX ( test01[Period] ),
        FILTER (
            ALL ( test01[Period] ),
            DATEVALUE ( REPLACE ( test01[Period], 1, 1, 0 ) )
                < DATEVALUE ( REPLACE ( MIN ( test01[Period] ), 1, 1, 0 ) )
        )
    )
VAR lastValue =
    CALCULATE (
        MAX ( test01[Value] ),
        FILTER ( ALL ( test01[Period] ), test01[Period] = lastPeriod )
    )
RETURN
    DIVIDE ( MIN ( test01[Value] ) - lastValue, lastValue, BLANK () )

yoy-calculation-in-DAX-with-data-in-veritical-format2

 

 

Best Regards,

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

Hi  ,

 

Thanks for the solution. It works perfectly.

 

Just wanted to understand how the Dax syntax will change if I have a date table for this syntax to work. The content of the date table is given below:

 

Date.JPG

 

I may be asking too many questions. However, I am working on a transition project, where I need to convert all my projects to Power BI and I am trying to do it as well as learn things simultaneously.

 

Look forward to your response.

 

Thanks,

Rohit

Hi@rohit403 

 

are you not able to import the data into the Power BI data model and shape it using Power Query?

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hi LivioLanzo,

 

I cant export or edit the data on the server, can just add measures and visualisations.

 

Thanks

LivioLanzo
Solution Sage
Solution Sage

Hi @rohit403 

 

I have uploaded a file here with the calculation for you.

It is with Excel, but in Power BI it works the same: https://1drv.ms/x/s!AiiWkkwHZChHj12jSeGdaQ9oAVmQ

 

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hi LivioLanzo,

 

First of all thanks for your prompt response.

 

However the challenge that I am facing is I have a huge data set in the same format (vertical/long). I am using this data set for creating charts for a report (which need the data to be in vertical format). Now when I have to calculate YoY % change, I have to use the same dataset.

 

So preferably, I am looking for a DAX formula which from the same dataset (in vertical format) can calculate YoY change.

 

Thanks,

Rohit

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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