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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SimonHarris
Regular Visitor

Sales averages for "asymmetrical" grouped years

Hi all , my fist message in this great forum!   

I'm trying to build a table & visuals for revenus by year.  The challenge I have is : I need to display the average yearly sales for a groupe of dates ( 2017-2018-2019) compared to singles years totals (2020, 2021, 2022, 2023).  I know that I could use an averrage function for all since single years yould be divided by one and not affect the results, but dealing with the grouped dates goes beond my current DAX expertise.  I'm using a date table. 

 

Thank you in advance!

 

Simon 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@SimonHarris , You can create measures like

calculate(Averagex(Values(Table[Year]), calculate(Sum(Table[Value])) ), Table[Year] in {2017,2018,2019})

 

calculate(Averagex(Values(Table[Year]), calculate(Sum(Table[Value])) ), Table[Year] in {2020, 2021, 2022, 2023})

 

or you can use rolling

 

Rolling 4= CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-4,year))

 

 

Rolling 4= CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],eomonth(MAX('Date'[Date]),-48) ,-3,year))

 

You can also try window function

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

View solution in original post

2 REPLIES 2
SimonHarris
Regular Visitor

Many thanks! 

amitchandak
Super User
Super User

@SimonHarris , You can create measures like

calculate(Averagex(Values(Table[Year]), calculate(Sum(Table[Value])) ), Table[Year] in {2017,2018,2019})

 

calculate(Averagex(Values(Table[Year]), calculate(Sum(Table[Value])) ), Table[Year] in {2020, 2021, 2022, 2023})

 

or you can use rolling

 

Rolling 4= CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-4,year))

 

 

Rolling 4= CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],eomonth(MAX('Date'[Date]),-48) ,-3,year))

 

You can also try window function

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.