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
Kugelianer91
Regular Visitor

Average of the last four weeks aka four previous rows

Hi,

 

I'm having a dataset of costs and would like to forecast the costs based on the average IS-values (Sum of Gesamtkosten) of the past four weeks based per type of cost (Kostenposten).

I've been trying to work sth. out like

CALCULATE(AVERAGEX(TOPN(4, Database, Database[KST], ASC, Database[Kostenposten], ASC, Database[Wochenstart].[Date],ASC), Database[Gesamtkosten]
but it would only deliver the current value.
Could you please help me out on that one?
 
Bonus: If there's been a change of plan costs eg. in the past two weeks it'd be great to just use them for the forecast.
Thanks a lot! 🙂
Kugelianer91_0-1666824202344.png

 

 
 
 
3 REPLIES 3
v-rongtiep-msft
Community Support
Community Support

Hi @Kugelianer91 ,

I have created a simple sample, please refer to it to see if it helps you.

Create a column first.

weeknum = WEEKNUM('Table'[date],2)

Then create a measure.

Measure =
VAR _4weeks =
    MAX ( 'Table'[weeknum] ) - 3
RETURN
    AVERAGEX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[weeknum] >= _4weeks
                && 'Table'[weeknum] <= SELECTEDVALUE ( 'Table'[weeknum] )
        ),
        'Table'[desamtosten]
    )

vpollymsft_0-1666836409946.png

If I have misunderstood your meaning, please provide more details with your desired output and pbix file without privacy inforamtion.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Kugelianer91 , You need to take the help of the date table and week rank. Hope you mean continuous Week

 

new columns in date table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Avg Last 4 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), [Your Measure]) , FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Hi,

 

thank you very much for the quick reply. Very glad to have such a responsive support.

Would it be possible reset the Forecast for different types aka "Kostenposten".

Currently I find Forecast-Values though there ain't no IS-Values at other "Kostenposten".

 

I have attached a screenshot where I calculated the scenarios exemplary.

Unfortunately I was unable to attach a pbix file.

Thank you very much in advance.

 

Kugelianer91_0-1666891561232.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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