Hi Everyone,
I have a formula which almost works, but is failing on one condition effecting a small number of events.
The purpose of the formula is to count the number of times an event has previously occured at a particular location within the past 10 years. So the first event returns a blank, the second event returns a 1, then 2 and so on.
There are conditions on the nature of the events that are counted, but the problem is that the events counted should be limited to those occuring within 10 years of the current event/row being iterated over. The counts work as intended, except where an event occured more than 10 years ago (this old event is being counted in error)
Can anyone point out any obvious faults or how to correct this?
Many thanks in advance!
Count_Of_Previous_Events =
CALCULATE (
COUNTROWS( Dataset),
FILTER (
Dataset,
[Rpt_candidate] = TRUE
&& [Crit1] = "Foo"
&& EARLIER ( [Crit2] ) = "Bar"
&& EARLIER ( [Crit1] ) = "Foo"
&& EARLIER ( [Crit3] ) = [Crit3]
&& EARLIER ( [Unique_REF] ) <> [Unique_REF]
&& EARLIER ( [Event_DATE] ) > [Event_DATE]
&& EARLIER ( [Event_DATE] ) > [Event_Date_Minus10yr]
&& EARLIER ( [Logged_DATE] ) > [Logged_DATE]
)
)
Note: [Event_Date_Minus10yr] is calculated as follows:
Event_Date_Minus10yr = DATE( YEAR(Dataset[Event_DATE] -10), MONTH(Dataset[Event_DATE]), DAY(Dataset[Event_DATE]) )
Here is an example table illustrating the problem.
The last line "16NO44" should not return a count of 1. There have been two events where Crit3 = CN162580, but the first event occurred more than 10 years prior to the following Event_DATE and so should not be counted.
Unique_REF | Rpt_Candidate | Crit1 | Crit2 | Crit3 | Logged_DATE | Event_DATE | Event_Date_Minus10yr | Count_Of_Previous_Events |
12NO25 | TRUE | Foo | Bar | NX103147 | 04/05/2012 | 08/02/2012 | 08/02/2012 | |
15NO3B | TRUE | Foo | Bar | NX103147 | 11/12/2015 | 03/11/2015 | 03/11/2015 | 1 |
16NO41 | TRUE | Foo | Bar | NX103147 | 12/10/2016 | 12/10/2016 | 12/10/2016 | 2 |
06NO0F | TRUE | Foo | Bar | CN162580 | 29/11/2006 | 29/11/2006 | 29/11/2006 | |
16NO44 | TRUE | Foo | Bar | CN162580 | 01/12/2016 | 01/12/2016 | 01/12/2016 | 1 |