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

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


Anonymous
Not applicable

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
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.