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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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