Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
i need to calculate the display the average of past working week in this table instead of the total quantity.
anyone can help me create DAX for this problem. thanks in advance.
Hi @Jonjon_99 ,
Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It would be helpful for the others in the community if they face the similar problem as yours. Thank you.
Solved: Calculate Dynamic Rolling 4 Week Average based on ... - Microsoft Fabric Community
Rolling 4 Weeks =
VAR _table =
CALCULATETABLE (
VALUES ( 'data'[Fiscal Week Number] ),
FILTER (
ALLSELECTED ( 'data'[Fiscal Week Number] ),
'data'[Fiscal Week Number]
>= MAX ( 'data'[Fiscal Week Number] ) - 3
&& 'data'[Fiscal Week Number] <= MAX ( 'data'[Fiscal Week Number] )
)
)
RETURN
IF(COUNTAX(_table,[Fiscal Week Number])=4,AVERAGEX ( _table, CALCULATE ( SUM ( 'data'[Actual] ) ) ))
Power BI Weekly Rolling Average | Weekly Moving Averag
Otherwise, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:
How to provide sample data in the Power BI Forum
Best Regards
To calculate the average quantity for the previous 5 working weeks in DAX, you can create a **measure** that dynamically calculates the average based on the previous 5 weeks. Here's a step-by-step guide to achieve this:
### 1. **Create a Measure for 5-Week Average**
This measure will take the context of the current week and calculate the average of the past 5 weeks dynamically. Here’s the DAX formula you can use:
```DAX
Average_5_Weeks =
VAR CurrentWeek = MAX('Table'[Week]) -- Assume 'Week' column identifies each working week uniquely
VAR Past5Weeks =
FILTER(
ALL('Table'),
'Table'[Week] <= CurrentWeek && 'Table'[Week] > CurrentWeek - 5
)
RETURN
AVERAGEX(Past5Weeks, 'Table'[Quantity]) -- Replace 'Quantity' with your actual column name
```
### Explanation of the Measure
- **CurrentWeek**: This variable identifies the current week in the table's context.
- **Past5Weeks**: This variable creates a table of the previous 5 weeks (using `FILTER` to get only rows where the `Week` is within the last 5 weeks).
- **AVERAGEX**: Calculates the average quantity over the filtered table of the past 5 weeks.
> Replace `'Table'` with your actual table name and `'Quantity'` with the column that holds the quantity values.
### 2. **Apply the Measure in Your Matrix or Table Visual**
- Place this measure in your table or matrix visual instead of using the `SUM` or `TOTAL` aggregation.
- This will ensure that each week in the visual displays the average quantity for the preceding 5 weeks.
### 3. **Handle Missing Data**
If some weeks do not have data, the formula above will still work as it calculates the average over available weeks within the range. If you want to ensure exactly 5 weeks of data, add logic to exclude periods with fewer than 5 weeks of data.
### Example Result
For each row in your table, the measure `Average_5_Weeks` will calculate the average of the previous 5 weeks, displaying it in place of the total quantity.
If this solution brightened your path or made things easier, please consider giving kudos. Your recognition not only uplifts those who helped but inspires others to keep contributing for the good of our community!
Can you show me the desired results? By previous 5 working weeks I am not sure if you mean, for example at 202005 for alcoholic beverages the number would be (50+99+99+15)/5 or something else. And how would you like the values between 202001 to 202004 be (where previous "5 weeks" are not all available).
this is the correct screenshot
Hi @Jonjon_99
Please refer to the linked discussion:
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
84 | |
76 | |
75 | |
43 | |
36 |
User | Count |
---|---|
109 | |
56 | |
52 | |
48 | |
43 |