Forum Discussion

PaulG572's avatar
PaulG572
New Member
7 years ago
Solved

Count rows based on dates from 2 separate tables

Hi community,   I am struggling to create a calculated column that counts activities per account between dates from different tables and was wondering if anyone can help? The table schemas are as b...
  • Anonymous's avatar
    Anonymous
    7 years ago
    [# Activities (30D)] = -- column in tblAccounts
    var __daysDiff = 30
    var __daysOpen = tblAccounts[DaysOpen]
    var __account = tblAccounts[AccountID]
    var __openDate = tblAccounts[OpenDate]
    var __endDate = __openDate + __daysDiff
    var __activityCount =
    	COUNTROWS(
    		FILTER (
    			tblActivities,
    			tblActivities[AccountID] = __account
    			&& tblActivities[Date] >= __openDate
    			&& tblActivities[Date] <= __endDate 
    		)
    	)
    RETURN
    	if(
    		__daysOpen >= __daysDiff,
    		__activityCount
    	)

    Best

    D.