Forum Discussion
3 Year Claims using Policy Level Context - Applying Context Transition
- 1 year ago
Hi all,
Apologies for the slow reply on this. I've come up with a working solution, specifically, creating a dummy column linking to a policy term and then creating a bi-directional relationship to establish a max date relative to the dimension.
I've provided the code below for those who may find this useful.
VAR MaxDate =MAX ( 'Date Table'[Date] )VAR ClaimsTable =ADDCOLUMNS (CALCULATETABLE(VALUES ( Claims[PolicyNumber] ), REMOVEFILTERS('Date Table')),"GWP",VAR RenewalDate =-- Bidirectional relationship to Dimension table to establish the max date relative to date aboveCALCULATE (MAX ( 'Policy Term'[PolicyTermStartDate] ),'Policy Term'[PolicyTermStartDate] <= MaxDate,CROSSFILTER ( 'Policy Term'[PolicyNumber], Claims[PolicyNumber], BOTH ),USERELATIONSHIP ( 'Policy Term'[PolicyNumber], Claims[PolicyNumber] ), --Default relationship is usually the term IDREMOVEFILTERS('Date Table'))VAR ThreeYearStart =EDATE ( RenewalDate, -36 )VAR CutOff =EDATE ( RenewalDate, -3 )RETURNCALCULATE (SUM ( Claims[GrossIncurred] ),Claims[EventDate] <= CutOff && Claims[EventDate] >= ThreeYearStart,Claims[TransactionDate] <= CutOff,REMOVEFILTERS ( 'Date Table' )))RETURNSUMX ( ClaimsTable, [GWP] )
Any feedback on optimisation would be appriciated though!Thanks,
Will
Hi Freece4802 ,
Here’s a DAX measure pattern that will reliably count the total claims per Policy, looking back 3 years from the renewal date (works even if the Policy table isn’t in your visual):
Claims in Last 3 Years =
VAR SelectedTerm = SELECTEDVALUE('Policy Term'[PolicyTermID])
VAR CurrentPolicyNumber =
CALCULATE(
MAX('Policy'[PolicyNumber]),
'Policy Term'[PolicyTermID] = SelectedTerm
)
VAR RenewalDate =
CALCULATE(
MAX('Policy'[RenewalDate]),
'Policy Term'[PolicyTermID] = SelectedTerm &&
'Policy'[PolicyNumber] = CurrentPolicyNumber
)
VAR StartDate = EDATE(RenewalDate, -36) // Go back 3 years
RETURN
CALCULATE(
COUNTROWS('Claims'),
'Claims'[PolicyNumber] = CurrentPolicyNumber,
TREATAS(
DATESBETWEEN('Date'[Date], StartDate, RenewalDate),
'Claims'[IncidentDate]
)
)
This measure uses TREATAS to filter your Claims table by incident date, only counting claims within the right 3-year window for each policy’s renewal. The logic is flexible it’ll work at month or day level, and will respect whatever context you set in your visuals. If your claims table is linked via a different key or you only have PolicyTermID in your visuals, you might need to adjust the variable part, but this pattern should get you 95% of the way there. If you need a simplified version (say, you’re already visualizing by Policy Term and Renewal Date is in context), you can shorten it:
Example with TREATAS:
Claims in Last 3 Years =
VAR RenewalDate = MAX('Policy'[RenewalDate])
VAR StartDate = EDATE(RenewalDate, -36)
RETURN
CALCULATE(
COUNTROWS('Claims'),
TREATAS(
DATESBETWEEN('Date'[Date], StartDate, RenewalDate),
'Claims'[IncidentDate]
)
)
This pattern will keep everything dynamic, so even if you slice or aggregate by month/year, you’ll always get the correct claim counts per policy’s 3-year lookback.
Hi rohit1991, I've tried the above and it still hasn't provided me with right information. This is likely because the Renewal Date isn't within the Dim policy table but either the fact policy transaction table or the Dimension Policy Term. I've added some additional Comments on this to burakkaragoz, which I assume will help answer the initial question.
Thanks,
- rohit19911 year agoSuper User
Hi Freece4802 ,
Based on everything you've shared including that the Renewal Date lives in the Fact Policy table, and Claims are linked via common dimensions like PolicyNumber and possibly PolicyTermID here’s a refined DAX measure that should give you accurate results across all visuals, even with slicing:
Claims in Last 3 Years = VAR SelectedTerm = SELECTEDVALUE('Policy Term'[PolicyTermID]) VAR CurrentPolicyNumber = CALCULATE( MAX('Policy Term'[PolicyNumber]), 'Policy Term'[PolicyTermID] = SelectedTerm ) VAR RenewalDate = CALCULATE( MAX('Fact Policy'[RenewalDate]), 'Fact Policy'[PolicyTermID] = SelectedTerm && 'Fact Policy'[PolicyNumber] = CurrentPolicyNumber ) VAR StartDate = EDATE(RenewalDate, -36) RETURN CALCULATE( COUNTROWS('Claims'), 'Claims'[IncidentDate] >= StartDate && 'Claims'[IncidentDate] <= RenewalDate, 'Claims'[PolicyNumber] = CurrentPolicyNumber, 'Claims'[PolicyTermID] = SelectedTerm )If your Claims table doesn’t have PolicyTermID, you can replace that part with a TREATAS statement to bridge it through dimension logic.
- Freece48021 year agoFrequent Visitor
Hi rohit1991 - I applied the above and when looking at the results they all returned a blank record, I then returned the SELECTEDVALUES and this too returned a blank value, does the above not require the policy term to be within the context of the visual? perhaps this is why?