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
kanth123
Helper I
Helper I

Show difference of sales for various years.

Hi 

Is it possible to have difference of sales between Years for current visual ? 

 

Sales are from Fact table.

Years and Month from Date table. 

 

kanth123_0-1706818502967.png

Thanks,

Srikanth

2 ACCEPTED SOLUTIONS
Daniel29195
Super User
Super User

@kanth123 

create w measure as follow : 

measure = 

var current_year =  max(dimdate[year])

var prev_year =  current_year - 1

var current_year_calc =  sum(tbl_name[col_name])

var prev_year_calc

calculate ( 

sum(tbl_name[col_name]),

all(dimdate),

dimdate[year] = prev_year,

values(dimdate[month])

)
)

 

return 

current_year_calc - prev_year_calc 

 

 

let me know if it works for you .

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

 

View solution in original post

@kanth123 

 

you can just add a switch statement at the end, 

switch(

true() , 

current_sales = 0 ||  prev_sales = 0  , 0 ,  [your calculation]) 

 

 

let me know if you need any other help .

 

 

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@kanth123 Should be: Better Year Over Year Change - Microsoft Fabric Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for video. helped in creating optimized measures. 

Daniel29195
Super User
Super User

@kanth123 

create w measure as follow : 

measure = 

var current_year =  max(dimdate[year])

var prev_year =  current_year - 1

var current_year_calc =  sum(tbl_name[col_name])

var prev_year_calc

calculate ( 

sum(tbl_name[col_name]),

all(dimdate),

dimdate[year] = prev_year,

values(dimdate[month])

)
)

 

return 

current_year_calc - prev_year_calc 

 

 

let me know if it works for you .

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

 

This helps but not 100%,  when there are no sales in Current or Prior year it should be 0. 

@kanth123 

 

you can just add a switch statement at the end, 

switch(

true() , 

current_sales = 0 ||  prev_sales = 0  , 0 ,  [your calculation]) 

 

 

let me know if you need any other help .

 

 

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.