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

100% stacked column chart this year vs last year comparison

Hello Comunity,

 

is there a possibility to display the value of the last year based on a simple selection, for example, if the year 2021 is selected, it still shows me the year 2020 in addition, as the stacked column chart only allows me to pull in one value?

 

ys034_0-1643294917922.png

 

MyMeasures: 

Total Sales = SUM('DataTable'[Sales])
Total Sales LY = CALCULATE(SUM('DataTable'[Sales]),SAMEPERIODLASTYEAR('DataTable'[Date].[Date]))
1 ACCEPTED SOLUTION

Hi @ys034 ,

 

Here's a screenshot of the test I ran, and @amitchandak 's formula was able to return the correct results. Could you please share your PBIX file?

 

vkkfmsft_0-1643780798732.png

 

Best Regards,
Winniz

 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@ys034 , If you want to show two years. by selecting one year. You need an independent date table too

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = date(year(_max)-1,1,1)
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

thank you very much,

If 2021 is filtered it shows me last year what about if I filter 2020 and want to show me 2019 and so on.

With the current solution, it no longer shows me anything as soon as I filter 2020.

 

Are there any solutions for this?

Hi @ys034 ,

 

Here's a screenshot of the test I ran, and @amitchandak 's formula was able to return the correct results. Could you please share your PBIX file?

 

vkkfmsft_0-1643780798732.png

 

Best Regards,
Winniz

 

i looked at your example file and now it works i had the calculation in the wrong table

 

thanks a lot

The calculation works, but I only want to compare the filtered year with the one from last year, i.e.
2021 vs 2020, 2020 vs 2019 if I select 2021 it shows me all data retroactively

ys034_0-1643799617877.pngys034_1-1643799648240.png


MyMeasure: 

Measure = var _max =MAXX(ALLSELECTED(Dates1),Dates1[Date].[Year])
var _min = DATE(YEAR(_max)-1,1,1)
return CALCULATE(SUM('DataTable'[Total Sales Local Currency]),FILTER(Dates,Dates[Date].[Year] >= _min && Dates[Date].[Year] <=_max))

 

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.