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
Anonymous
Not applicable

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
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

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.

View solution in original post

2 REPLIES 2
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

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.
Anonymous
Not applicable

Thanks Much Dina 🙂

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.