cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
drbr
Helper II
Helper II

Calculate measure start/initial date for last 3 occured events/values

I've been struggling with how to dynamically calculate measure with date output of the last 3 values that occur on specific dates. The measure should output dates as simulated on the image.
Any help would be very much appreciated.
I need to solve it with measure, so no calculated columns.
Beware: it's not an easy one😁

 

tGfe0tT

1 ACCEPTED SOLUTION
drbr
Helper II
Helper II

I've managed id to do it with a measure. I will still do some tweaking to the code, but the concept is clear and in the end, it was not that hard🙂

oE4uPNP

Measure =
VAR Selecteddate_ = SELECTEDVALUE(T[Date])
VAR CountPositiveDates_ = CALCULATE(COUNTROWS(T), DATESBETWEEN(T[Date],DATE(2000,1,1),Selecteddate_),T[Value]>0)
VAR TargetCount_ = CountPositiveDates_ - 2 //use n-1 for proper segments
VAR TmpTable_ = SUMMARIZE(ALL(T),T[Date],"Check",IF(SUM(T[Value])>0,CALCULATE(COUNTROWS(T), DATESBETWEEN(T[Date],DATE(2000,1,1),T[Date]),T[Value]>0),BLANK()))

RETURN
SUMX(FILTER(TmpTable_,[Check] = TargetCount_),[Date])

View solution in original post

3 REPLIES 3
drbr
Helper II
Helper II

I've managed id to do it with a measure. I will still do some tweaking to the code, but the concept is clear and in the end, it was not that hard🙂

oE4uPNP

Measure =
VAR Selecteddate_ = SELECTEDVALUE(T[Date])
VAR CountPositiveDates_ = CALCULATE(COUNTROWS(T), DATESBETWEEN(T[Date],DATE(2000,1,1),Selecteddate_),T[Value]>0)
VAR TargetCount_ = CountPositiveDates_ - 2 //use n-1 for proper segments
VAR TmpTable_ = SUMMARIZE(ALL(T),T[Date],"Check",IF(SUM(T[Value])>0,CALCULATE(COUNTROWS(T), DATESBETWEEN(T[Date],DATE(2000,1,1),T[Date]),T[Value]>0),BLANK()))

RETURN
SUMX(FILTER(TmpTable_,[Check] = TargetCount_),[Date])

View solution in original post

amitchandak
Super User IV
Super User IV

@drbr , Create two new columns and try

 

rank = rankx(filter(table, table[value]=1]),[Date],,asc,dense)


new column =
var _1 = Table[rank]
return
maxx(filter(Table, Table[rank] =_1-2 ),Table[Date])



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

@amitchandak  thank you very much. I replied soon after your reply. Unfortunately and I don't know why my answer was not posted. Firstly, thank you for your answer. I guess you missed the part, that I am limited only to measures, so no calculated columns at all
Do you or anyone have any ideas in this context?

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are You Ready?

Test your skills now with the Cloud Skills Challenge.

Top Solution Authors