cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Vsna Frequent Visitor
Frequent Visitor

Rolling one month Average of sum of a column on each day

Hi, 

I have a table -

IDDateSerialNumQty
17/11/20191080
17/11/201910100
27/11/201911100
37/11/20191220
37/11/20191230
17/12/20191340
17/12/20191350
27/12/20191440
27/12/201914100
37/12/201915300
17/13/20191620
27/13/20191730
37/13/20191840
37/13/20191810
37/13/20191860

I want to find out what is the average number of quantities on particular day(according to the data in above table, rolling 2 days):  The desired output is :

Rolling avarage 2 days Date
  
4307/12/2019
3457/13/2019

 

If I break it down in steps, this is what I want as output:

Sum Per dayRolling avarage 2 days Date
330 7/11/2019
5304307/12/2019
1603457/13/2019

Currently I'm using this code -

Rolling2Day = CALCULATE(AVERAGE(Sheet1[Qty]),DATESINPERIOD (
'Sheet1'[Date],
LASTDATE ( 'Sheet1'[Date] ),
-2,
DAY
)
)
The output is :
DateRolling 2Day
7/11/201966
7/12/201986
7/13/201969
  

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Rolling one month Average of sum of a column on each day

Hi @Vsna 

 

You can use M code to group table and add index column in query editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc9JDsAgCAXQu7A2kcGpZzHe/xrVNpFKrBtC8iB8agUCB9kTeUa6ek/YS0Fo7scIX2SL9EGxOKb5YLJc5GljOBwsLmHUgu5tzQRVjE+Y5aJMTPoFW8v6hVgrmmZrdLDUrd0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, SerialNum = _t, Qty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"SerialNum", Int64.Type}, {"Qty", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", each List.Sum([Qty]), type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1)
in
#"Added Index"

Then add the measure to generate the rolling average:

Measure = var lastindex = MAX(Table1[Index])-1
var lastcount = CALCULATE(MAX(Table1[Count]),FILTER(ALL(Table1),[Index]=lastindex))
Return
IF(lastindex=0,BLANK(),DIVIDE(MAX(Table1[Count])+lastcount,2))

3.png

Best regards,

Dina Ye

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Community Support Team
Community Support Team

Re: Rolling one month Average of sum of a column on each day

Hi @Vsna 

 

You can use M code to group table and add index column in query editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc9JDsAgCAXQu7A2kcGpZzHe/xrVNpFKrBtC8iB8agUCB9kTeUa6ek/YS0Fo7scIX2SL9EGxOKb5YLJc5GljOBwsLmHUgu5tzQRVjE+Y5aJMTPoFW8v6hVgrmmZrdLDUrd0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, SerialNum = _t, Qty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"SerialNum", Int64.Type}, {"Qty", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", each List.Sum([Qty]), type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1)
in
#"Added Index"

Then add the measure to generate the rolling average:

Measure = var lastindex = MAX(Table1[Index])-1
var lastcount = CALCULATE(MAX(Table1[Count]),FILTER(ALL(Table1),[Index]=lastindex))
Return
IF(lastindex=0,BLANK(),DIVIDE(MAX(Table1[Count])+lastcount,2))

3.png

Best regards,

Dina Ye

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Vsna Frequent Visitor
Frequent Visitor

Re: Rolling one month Average of sum of a column on each day

Thanks Much Dina Smiley Happy

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 391 members 3,619 guests
Please welcome our newest community members: