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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CP525
New Member

7 day moving average of measure

Hi all,

 

so I'm struggling to create a 7 day moving average of a measure I created.

 

The measure is set up as follows:

 
WE rate =
DIVIDE(
    SUM('factWE'[WE value]),
    SUM('factPO'[PO value]),
    0
) *100
 

It gives back the percentage of goods receipt by orders. I visualized it to see how the percentage improves over time. There is a huge variation in the data, so I wanted to smooth it with a 7 day moving average, but I'm unable to create the correct DAX formula for that. My main problem is that I can't use the average function as this formula cannot reference to the measure.

 

Any tips on that?

1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @CP525 ,

 

Based on your description,
I created some data:

vweiyan1msft_0-1705908050789.png

Please try the following steps:
1.Please try code as below to create Calculated Column.

Mod = 
VAR _rank = RANKX(ALL('Table'),'Table'[date],,ASC)
VAR _mod=MOD(_rank,7)
RETURN
IF(_mod=1,
    1,
    0)
Group = CALCULATE(SUM('Table'[Mod]),
                  FILTER(ALL('Table'),'Table'[date]<=EARLIER('Table'[date]))
                )

2. Use the following code to create a Measure.

Measure = 
var _1 = MAX('Table'[Date])
return
AVERAGEX(
    FILTER(
        SUMMARIZE(ALL('Table'),
        'Table'[Date],'Table'[Group],
        "Avg value",AVERAGEX('Table',[Rate])),
        'Table'[Date] <= _1 && 'Table'[Group] = MAX('Table'[Group])
        ),
        [Avg value]
)

Result is as below.

vweiyan1msft_2-1705908375429.png

 

Is this the result you expect?
If I've misunderstood you, please provide detailed sample data and the results you are hoping for. We can better understand the problem and help you. Show it as a screenshot or excel. Please remove any sensitive data in advance.

 

Best Regards,
Yulia Yan

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

View solution in original post

2 REPLIES 2
v-weiyan1-msft
Community Support
Community Support

Hi @CP525 ,

 

Based on your description,
I created some data:

vweiyan1msft_0-1705908050789.png

Please try the following steps:
1.Please try code as below to create Calculated Column.

Mod = 
VAR _rank = RANKX(ALL('Table'),'Table'[date],,ASC)
VAR _mod=MOD(_rank,7)
RETURN
IF(_mod=1,
    1,
    0)
Group = CALCULATE(SUM('Table'[Mod]),
                  FILTER(ALL('Table'),'Table'[date]<=EARLIER('Table'[date]))
                )

2. Use the following code to create a Measure.

Measure = 
var _1 = MAX('Table'[Date])
return
AVERAGEX(
    FILTER(
        SUMMARIZE(ALL('Table'),
        'Table'[Date],'Table'[Group],
        "Avg value",AVERAGEX('Table',[Rate])),
        'Table'[Date] <= _1 && 'Table'[Group] = MAX('Table'[Group])
        ),
        [Avg value]
)

Result is as below.

vweiyan1msft_2-1705908375429.png

 

Is this the result you expect?
If I've misunderstood you, please provide detailed sample data and the results you are hoping for. We can better understand the problem and help you. Show it as a screenshot or excel. Please remove any sensitive data in advance.

 

Best Regards,
Yulia Yan

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

Corey_M
Resolver I
Resolver I

can you provide what your tables look like, and if you have a date table with a relationship to factWe and FactPO?

 

The solution is gonna involve using:

Calculate and

DATESINPERIOD (
        Table[Date],
        LASTDATE ( Table [Date] ),
        -7,
        DAY
    )

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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