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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors