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
LRiley
Frequent Visitor

Average over an 28 day period

Hi all,

I'm hoping someone can help, I've been trying to Create a measure to work out an average of a column which has 1 & 0 over a 28 day period so when this is grouped by month or week in a matrix it would average the column 

Average over 28 day period = 
	VAR LAST_DATE = FIRSTDATE( 'Query1'[ORDERDATE].[Date])
	RETURN
		AVERAGEX(
			DATESBETWEEN(
				'Query1'[ORDERDATE].[Date],
				LAST_DATE,
				DATEADD(LAST_DATE,28,DAY)
			),
			CALCULATE(AVERAGE('Query1'[Call Driver]))
		)

This was my last attempt to create a measure.

 

as a calculated column, I would have used this 

Average over 28 days = 
VAR 28daysafter = [ORDERDATE] + 28
VAR IDtoCheck = [AGENTID]
RETURN
    CALCULATE (
        AVERAGE(Query1[Call Driver]),
        ALL(Query1),
        'Query1'[AGENTID] = IDtoCheck,
        Query1[ORDERDATE]+1 <= 28daysafter
    )

Any help would be appreciated 

 

Thanks 

Liam

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi LRiley,

 

According to your description, it seems that you want to calculate rolling average based on month and id, right? If so, you could try to use below measure to see whether it work or not

rolling sum =
CALCULATE (
    SUM ( avg28[amount] ),
    FILTER (
        ALL ( avg28 ),
        avg28[date]
            <= MIN ( avg28[date] ) + 28
            && avg28[date] >= MIN ( avg28[date] )
            && avg28[id] = MIN ( avg28[id] )
            && avg28[month] = MIN ( avg28[month] )
    )
)

rolling avg = [rolling sum]/28

66.png

If this is not what you want, please correct me and inform me more detailed information(such as your sample data and expecting output), then I will help you more correctly.

 

 

Best Regards,

Zoe Zhi

 

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

1 REPLY 1
dax
Community Support
Community Support

Hi LRiley,

 

According to your description, it seems that you want to calculate rolling average based on month and id, right? If so, you could try to use below measure to see whether it work or not

rolling sum =
CALCULATE (
    SUM ( avg28[amount] ),
    FILTER (
        ALL ( avg28 ),
        avg28[date]
            <= MIN ( avg28[date] ) + 28
            && avg28[date] >= MIN ( avg28[date] )
            && avg28[id] = MIN ( avg28[id] )
            && avg28[month] = MIN ( avg28[month] )
    )
)

rolling avg = [rolling sum]/28

66.png

If this is not what you want, please correct me and inform me more detailed information(such as your sample data and expecting output), then I will help you more correctly.

 

 

Best Regards,

Zoe Zhi

 

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

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.