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
Aina-
Frequent Visitor

DAX measure: Year to year difference

How do i calculate year to year diffrence if my data type is in a whole number and not in "date" datatype. I only have sales data for 2021 and 2022. There are no month and day data. Most of tutorial/solution that I watch use calendar(dim date). But in my case I used only years data only which is in whole number datatype.

 

 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1683459876756.png

Sales: = 
SUM( Sales[Sales] )

 

Sales diff ratio: = 
VAR _currentyear =
    MAX ( Sales[Year] )
VAR _salescurrentyear =
    CALCULATE ( [Sales:], Sales[Year] = _currentyear )
VAR _salesprevyear =
    CALCULATE ( [Sales:], Sales[Year] = _currentyear - 1 )
RETURN
    DIVIDE ( _salescurrentyear - _salesprevyear, _salesprevyear )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1683459876756.png

Sales: = 
SUM( Sales[Sales] )

 

Sales diff ratio: = 
VAR _currentyear =
    MAX ( Sales[Year] )
VAR _salescurrentyear =
    CALCULATE ( [Sales:], Sales[Year] = _currentyear )
VAR _salesprevyear =
    CALCULATE ( [Sales:], Sales[Year] = _currentyear - 1 )
RETURN
    DIVIDE ( _salescurrentyear - _salesprevyear, _salesprevyear )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi Kim, thank you so much for the answer. It's worked for data that only contain (2 years) 2022 and 2021. May I know what should I do for the 10 years data from 2011 until 2022 ? I need to find the differences of each year with the previous year. I try using your method but there is no changes in my data when I select one of the year within 10 years 

 

Hi,

Please provide your sample pbix file's link, and the expected outcome of how the visualization looks like.

And then I can try to look into it to come up with a solution.

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.