cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KyriakosT
Helper I
Helper I

Find current trend in time series

Hello,

 

I have a (sparse) time series table and I want to calculate the current trend based only on the last 3 values.

I think the slope of trend line (Linear Regression) could be considered as the current trend.

I' ve found code describing the DAX Linear Regression calculation but it is based on all previous values.

 

I know it might be silly but I'm stack. 

Can you please suggest a workaround?

Thank you in advance. 

 

IDDatetime Value
11/1/2021 8:00:25 0.24
21/1/2021 9:45:10 0.24
31/1/2021 14:35:38 0.29
42/1/2021 11:12:00 0.28
52/1/2021 19:43:29 0.27
63/1/2021 7:17:12 0.26

 

1 ACCEPTED SOLUTION
TomMartens
Super User II
Super User II

Hey @KyriakosT ,

 

i created this simple measure:

 

just the average value = 
CALCULATE(
    AVERAGE( 'Table'[Value] )
)

 

and this more complex one, here I use TOPN to find the previous 3 values

 

the average of the last 3 datetimes = 
var __datetime = MAX( 'Table'[Datetime] )
return
CALCULATE(
    [just the average value]
    , TOPN(
        3
        , FILTER( ALL('Table'[Datetime] ) , 'Table'[Datetime] < __datetime )
        , 'Table'[Datetime]
        , DESC
    )
    , ALL('Table'[ID] , 'Table'[Value])
)

 

it seems that the 2nd measure creates what you are looking for

image.png

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

1 REPLY 1
TomMartens
Super User II
Super User II

Hey @KyriakosT ,

 

i created this simple measure:

 

just the average value = 
CALCULATE(
    AVERAGE( 'Table'[Value] )
)

 

and this more complex one, here I use TOPN to find the previous 3 values

 

the average of the last 3 datetimes = 
var __datetime = MAX( 'Table'[Datetime] )
return
CALCULATE(
    [just the average value]
    , TOPN(
        3
        , FILTER( ALL('Table'[Datetime] ) , 'Table'[Datetime] < __datetime )
        , 'Table'[Datetime]
        , DESC
    )
    , ALL('Table'[ID] , 'Table'[Value])
)

 

it seems that the 2nd measure creates what you are looking for

image.png

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors