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
micsafdas
Frequent Visitor

Previous Year average and 2 year average

Hello!

I'm stuck and it would be great if you Experts could help me.

 

I do have a measure which calculates the monthly rents. What I would need is a average bar for the last and the second to last year.

 
 
 
 

The measure to calculate the monthly rent for reference:

Rent actual =
CALCULATE(SUM('Erlöse'[Betrag]); 'Erlöse'[Positionsart] IN { "Miete" })
 
If you need anything else to answer the question, I'm happy to share.
 
Thanks in advance!
1 ACCEPTED SOLUTION

I managed to solve it my self, once I got inspired by amitchandak's solution. 🙂

 

Its

Average last year = CALCULATE(SUM('Erlöse'[Betrag])/12;PREVIOUSYEAR(Datumstabelle[Date]);'Erlöse'[Positionsart] IN { "Miete" } )

and

Average second to last year = CALCULATE(SUM('Erlöse'[Betrag])/12;PARALLELPERIOD(Datumstabelle[Date];-2;YEAR);'Erlöse'[Positionsart] IN { "Miete" } )

 

Simple as that... ^^

 

Thanks all

View solution in original post

6 REPLIES 6
v-kelly-msft
Community Support
Community Support

Hi @micsafdas

 

You need 2 measures as below:

 

 

Last 2 years average = CALCULATE(AVERAGE('Table'[Value]),FILTER(CALCULATETABLE(ALLSELECTED('Table'),ALL('Table'[Date])),'Table'[Date].[Year]=YEAR(MAX('Table'[Date]))-2))
Previous year average = CALCULATE(AVERAGE('Table'[Value]),FILTER(CALCULATETABLE(ALLSELECTED('Table'),ALL('Table'[Date])),'Table'[Date].[Year]=YEAR(MAX('Table'[Date]))-1))

 

Finally you will see :

 

Annotation 2020-02-04 154143.png

 

For the related .pbix file,pls click here.

 

Best Regards,
Kelly

micsafdas
Frequent Visitor

powerbi.png

 

As I can't seem to be able to attach the graphic in the original post here what I am looking for.

In case you have date dimension

Last YTD complete Sales = CALCULATE(Avergae(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

Last to last YTD complete Sales = CALCULATE(Avergae(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-2,Year)),"12/31"))

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

@amitchandak 

Thanks for your post! This seems promising, but I didn't get the expected result back.

I probably explained it not to the fully extent.

 

I need (looking from 2019) the average of 2018, namely from 01.01.18 - 31.12.18 and from 2017 (vice versa)

No year to date calculations.

 

Btw, I do have a date table. To give it some "flesh", I uploaded the basic pbix which translates to the big pbix.

https://www.dropbox.com/s/u4wmq7puu5mzl05/Showcase.pbix?dl=0

 

I would expect the "Previous Year Average" to be at 4333 in 2018, as the sum of 2017 is 52K.

 

@v-kelly-msft 

Thanks also!

I couldn't get your code to work though. It doesn't seem to understand this part:

Datumstabelle[Date].[Year]

The [Year] seems to be the problem. Why so?

 

Thanks so far you two!

 

I managed to solve it my self, once I got inspired by amitchandak's solution. 🙂

 

Its

Average last year = CALCULATE(SUM('Erlöse'[Betrag])/12;PREVIOUSYEAR(Datumstabelle[Date]);'Erlöse'[Positionsart] IN { "Miete" } )

and

Average second to last year = CALCULATE(SUM('Erlöse'[Betrag])/12;PARALLELPERIOD(Datumstabelle[Date];-2;YEAR);'Erlöse'[Positionsart] IN { "Miete" } )

 

Simple as that... ^^

 

Thanks all

If you want sum first at month level and the Average

Avergaex(summarize(CALCULATETABLE('Erlöse', DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"), 'Erlöse'[Positionsart] IN { "Miete" })
	,date[month-year],"_sum",SUM('Erlöse'[Betrag])),_sum)

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.