Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 217137

Counting repeat events with dates and multiple conditions

$
0
0

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_REFRpt_CandidateCrit1Crit2Crit3Logged_DATEEvent_DATEEvent_Date_Minus10yrCount_Of_Previous_Events
12NO25TRUEFooBarNX10314704/05/201208/02/201208/02/2012 
15NO3BTRUEFooBarNX10314711/12/201503/11/201503/11/20151
16NO41TRUEFooBarNX10314712/10/201612/10/201612/10/20162
06NO0FTRUEFooBarCN16258029/11/200629/11/200629/11/2006 
16NO44TRUEFooBarCN16258001/12/201601/12/201601/12/20161

Viewing all articles
Browse latest Browse all 217137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>