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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PowerBI__
Frequent Visitor

12 Weeks orders Average based on slicer selection

Hello,
I have a table below:

Week Start DatePrice
3-Jun-2465
10-Jun-2465
17-Jun-2487
24-Jun-247
1-Jul-2497
8-Jul-24635
15-Jul-2497
22-Jul-247
29-Jul-24365
5-Aug-2497
12-Aug-24987
19-Aug-24685
26-Aug-24897
2-Sep-245
9-Sep-2478
16-Sep-24858
23-Sep-248
30-Sep-2458

Each row represents an order and price represents its price. I want to create a line graph which lets say if I select the slicer of date from range of 1st september till 30 September. It should show me the weekly average for orders and another measure for weekly average of price. In line graph lets say first week is 2 September then the value against it should be average of 2 september and previous 11 weeks and divided by 12. In the next week of 9th September in line graph the value should be 9th September+previous 11 weeks and divided by 12

5 REPLIES 5
v-jtian-msft
Community Support
Community Support

Hi,Selva-Salimi ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.


Hello,@PowerBI__ .I am glad to help you.

I hope my test below meets your expectations
For each week's data, dynamically display the average of the sales for the first 12 weeks of the corresponding week based on the minimum filtered value of the slicer (first summing, then directly dividing by 12)

The calculation logic I've written will only calculate the average of sales over the 12 weeks for a time span of 12 weeks or more. The current row of data for less than 12 weeks will be displayed as 0 (the existing minimum time to the current row of the date and time of the span of weeks is less than or equal to 11 weeks).

You need to modify the measure according to your actual needs. Or write a measure that meets your real computing environment.

Here is my test measure:

Avg_12weeks = 
VAR _minDate =
    MIN ( 'CalendarDate'[Date] )
VAR _startDay =
    CALCULATE (
        MIN ( 'Table'[Week Start Date] ),
        FILTER ( 'Table', 'Table'[Week Start Date] >= _minDate )
    )
VAR _selectedweekNum =
    CALCULATE (
        MIN ( 'Table'[WeekNum] ),
        FILTER ( 'Table', 'Table'[Week Start Date] = _startDay )
    )
VAR _startweekNum = _selectedweekNum - 11
VAR _sumSales =
    CALCULATE (
        SUM ( 'Table'[Price] ),
        FILTER (
            ALL ( 'Table' ),
            [WeekNum] >= _startweekNum
                && [WeekNum] <= _selectedweekNum
        )
    )
RETURN
    IF (
        CALCULATE (
            MIN ( 'Table'[WeekNum] ),
            FILTER ( ALL ( 'Table' ), [WeekNum] = _startweekNum )
        )
            = BLANK (),
        0,
        DIVIDE ( _sumSales, 12 )
    )
    // The calculation logic I've written will only calculate the average of sales over the 12 weeks for a time span of 12 weeks or more. The current row of data for less than 12 weeks will be displayed as 0 (the existing minimum time to the current row of the date and time of the span of weeks is less than or equal to 11 weeks).

vjtianmsft_1-1726641151999.png
Here is my test data:
vjtianmsft_2-1726641160307.png

vjtianmsft_3-1726641168102.png

vjtianmsft_4-1726641219166.pngvjtianmsft_5-1726641225741.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @v-jtian-msft ,
The issue I am getting is on count of orders. It is working on sum fine but not on count lets say if I want to take average order count I received in last 12 weeks

Hi,

This measure pattern should work

Total orders = counta(Data[Order number[)

Total order in 12 weeks ending = calculate([Total orders],datesbetween(calendar[date],min(calendar[date])-77,min(calendar[date])+7))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,@PowerBI__ .Thank you for your reply.
You can show your current problematic dax code, please share it as a pbix file on the forums and provide the corresponding screenshot of the code that doesn't contain sensitive data, this will help to help you quickly identify possible problems with the code.
URL:
How to Get Your Question Answered Quickly - Microsoft Fabric Community


Selva-Salimi
Solution Specialist
Solution Specialist

Hi @PowerBI__ 

 

you can follows these steps:

1. wite a column to have an order for weeks. this column could be written as follows:

    week_orders = calculate( count(week_start) , filter(your_table, week_start <= earlier (week_start))

2. write a measure using the previous column as follows:

    measure Avg_12M = calulate(sum(price) , filter (all(your_table) , week_order <= selectedvalue(week_order)-12 )) / 12

 

If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.