I need help calculating moving average of last 4 fiscal weeks in my data. We cannot use datesinperiod as I need to use "Week" in my steps. I have fiscalweek number ( for ex: 31, 32, 33 etc )
Please see excel version in the attached image.
Hi @amaddala ,
Based on your description, you can do some steps as follows.
Duplicate the “fiscal week” column-->split it by number of characters(left 6)-->remove the unnecessary column and rename the necessary one as “week”
Measure = IF(MAX('Sheet1'[week])<=4,0,AVERAGEX(FILTER(ALL(Sheet1),[week]<SELECTEDVALUE(Sheet1[week])&&[week]>=SELECTEDVALUE(Sheet1[week])-4),[Transaction#]))
Hope that's what you were looking for.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Your idea was helpful, but when I tried to apply this the result wasnt coming correctly. However, I created a new dax as below. It worked, but not sure what was the difference between your logic and mine.
But when I try to add any other dimension to this, the value remains the same.
Hi @amaddala ,
Could you please tell me what went wrong? Could you share some screenshots around the issue please? This is not helping much.
Add error screenshot as well which you are facing.
I tested it again with new data, and there were no errors.
You said that you want to calculate the moving average of the previous four weeks, but the formula you gave is the moving average of the previous six weeks.
Maybe I'm not getting what actually you are trying to do.
Thank you, I have just used 6 weeks instead of 4 with the same logic you shared as my business requirement changed. Below is the screenshot for what I am seeing with my code vs yours.
Hi @amaddala ,
It seems that nothing went wrong.
Can you share some sample data and the expected result to have a clear understanding of your question? I can do some tests for you.
You can save your files in OneDrive, Google Drive, or any other cloud sharing platforms and share the link here.
I am having trouble creating rank in the first place. I am getting the below error.
A single value for column 'fiscalweeknumber' in table 'Summaryold' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
@amaddala , this way week is sortable, hope you have W01.
Create a Rank on this , a new column
Week Rank = RANKX(all('Date'),'Date'[FiscalWeek],,ASC,Dense) //YYYYWW format
Try these measures - example measures
This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))
Last 4 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.