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
ekambulow
Regular Visitor

Moving Average of a time series

I am quite new to Power Bi.  I have a table that has 3 relevant columns:  Name, Values, and Time (sampled in seconds - not date tiime, so the precanned daily moving average methods don't work).  I'd like to create a moving average column which Groups by Name and then does a moving average for the Values.  I current have Scatter Charts that plot the Values vs Time  with the seelected Page Filtered Name as the legend.  I would like to instead plot the smoothed Values. 

How do I create a new column that does that.

1 ACCEPTED SOLUTION

Please define "simple" 🙂  I used a -1 to +1 window, you can change it to -2 to 0 (for example).

 

lbendlin_0-1707929859374.png

Smoothed = 
var w = WINDOW(-1,REL,1,REL,ALLSELECTED(Table2[RunTime]),ORDERBY(Table2[RunTime]))
return CALCULATE(average(Table2[Value]),w)

View solution in original post

12 REPLIES 12
ekambulow
Regular Visitor

This may highlight may inexperience with Queries - but I'll say what I uderstand.  When I create the original Power query,  I concanetated them.  My assumption is that it would maintain its order.  There is a colum of RunTime for each CSV.    I've just added an Index Column to the Power Query of the concanated CSVs -so now assuming the original temporal order is maintained the index should maintain the temperoral order.   I don't care what order the CSVs are, just that that runtime for each CSV is maintained (I will be comparing Values between RunTimes starting at 0 for each csv).    My plan was to build a Table/Column using DAX manipulating the original database PowerQuery. 

 My assumption is that it would maintain its order. 

That would be nice, wouldn't it?  Alas, there is no guarantee. 

 

Anyway, Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

This is a sample of the results that I am looking for.  I used a simple 3 point averaging.

IndexFilenameRunTimeValueSmoothed
1First.CSV00.12.7
2First.CSV134
3First.CSV254.5
4First.CSV344
52nd.CSV00.30.266667
62nd.CSV10.20.433333
72nd.CSV20.30.4
82nd.CSV30.80.4
92nd.CSV40.10.333333
102nd.CSV50.30.45
112nd.CSV60.60.6
123rd.CSV00.40.5
133rd.CSV10.30.433333
143rd.CSV20.80.633333
153rd.CSV30.20.6
163rd.CSV40.90.9
173rd.CSV50.71.266667
183rd.CSV61.12.366667
193rd.CSV725.666667
203rd.CSV847.5
213rd.CSV91111

 

What I am looking for is to be able to create a visual that will look like this:

ekambulow_0-1707921057269.png

 

Please define "simple" 🙂  I used a -1 to +1 window, you can change it to -2 to 0 (for example).

 

lbendlin_0-1707929859374.png

Smoothed = 
var w = WINDOW(-1,REL,1,REL,ALLSELECTED(Table2[RunTime]),ORDERBY(Table2[RunTime]))
return CALCULATE(average(Table2[Value]),w)

Have a related problem now.  
I use these function to try to normalize the results (and I have created a maxTable with a Many to 1 relationship).  I now get a circular reference errror. How should I approach this problem not to get this problem.

 

MaxTable= SUMMARIZECOLUMNS('Table2'[Filename],"V MAX",MAX('Table2'[Smoothed]))
NormV= 'Table2'[Smoothed] /RELATED(MaxTable[V MAX])

 

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

I think the information provide fully defines the problem - althought I don't know how to verify.  The simulated table provide above is Table 2.   I implemented your Smoothed function.  And then added MaxTable (based on Table 2) and a new  NormV column in Table 2 (along with adding the associated relationship) - I then go the error.   The only difference (that I am aware) between Table 2 and the real data is the size.

Can you post a sample PBIX that illustrates the issue?

Wow.  Thank you.  That is so amazingly simple!

ekambulow
Regular Visitor

Currently no, but I can add one to the main query (which is a concatenation of time series csvs) if that would help.  We can call that new column Index for the sake of this example.

Let me rephrase. How are you guaranteeing the temporal order of your data points?

lbendlin
Super User
Super User

Does your data have an index or row number column?

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.