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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.