Forum Discussion
3 Year Claims using Policy Level Context - Applying Context Transition
Hi all,
So I'm looking to create a Measure which calculates the total number of Claims by Policy 3 years prior to the renewal date of a Policy. For example:
Policy due 15/01/25 would have a 3 year context going back to 15/01/2022, whereas a Policy with a renewal date of 31/01/25 would have a 3 year context going back to 31/01/2025.
The design model is a standard Star Scheme, however, the model contains multiple fact tables, important points to call out.
1) A fact policy table will contain every policy available to renew, including the renewal date, however, this could also be obtained by a dimension which also contains every due date for each new policy term.
2) The Claims table may not have a claim for every year due to no incidents. - Consequently meaning you may not have a renewal date relative to the current year within your claim table
3) When presented to an audiance, this is also upscaled to a month level, not just a day level.
4) The policy number may often not be included within the visualisation so I need the context to specifically be within the measure and it will likely end with SUMX.
Any solution or guidance would be appriciated.
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
11 Replies
- danextianSuper User
Hi Freece4802
Please provide a workable sample data (not an image), your expected result from the same sample data and your reasoning behind. You may post a link to Excel or a sanitized copy of your PBIX stored in the cloud.
- burakkaragozSuper User
Hi Freece4802 ,
I understand you're working on a complex time intelligence scenario with policy renewals and claims data. Based on your description, I can provide a solution, but to ensure it's perfectly tailored to your model structure, I'd like to clarify a few details:
Quick questions to optimize the solution:
- Relationship structure: How are your Policy and Claims tables related? Is it a direct relationship via PolicyNumber, or do you have a bridge table?
- Claims amount vs count: You mentioned "total number of Claims" - are you looking for a COUNT of claim records or SUM of claim amounts?
- Date field in Claims: What's the name of your date field in the Claims table (ClaimDate, IncidentDate, etc.)?
Here's my initial approach based on your requirements:
3 Year Claims Count = SUMX( VALUES('Policy'[PolicyNumber]), VAR CurrentPolicy = 'Policy'[PolicyNumber] VAR RenewalDate = CALCULATE( MAX('Policy'[RenewalDate]), 'Policy'[PolicyNumber] = CurrentPolicy ) VAR ThreeYearStart = DATEADD(RenewalDate, -3, YEAR) RETURN CALCULATE( COUNTROWS('Claims'), 'Claims'[PolicyNumber] = CurrentPolicy, 'Claims'[ClaimDate] >= ThreeYearStart, 'Claims'[ClaimDate] < RenewalDate ) )
This handles your star schema structure and works at both day and month levels. However, if you can confirm those relationship details, I can refine this to be more precise for your specific model.
Would you mind sharing those clarifications so I can provide the most accurate solution?
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.- Freece4802Frequent Visitor
Hi burakkaragoz, See below for comments on your questions:
- Relationship structure: How are your Policy and Claims tables related? Is it a direct relationship via PolicyNumber, or do you have a bridge table? -Claims are Policies are connected by Common Dimensions and not a bridge table. So Dimension PolicyNuimber is present in both fact tables. Awakwardly enough, the start date can be obtained either by the Fact Policy Table, or a seperate dimension called Policy Term which relates to each term of a policy.
- Claims amount vs count: You mentioned "total number of Claims" - are you looking for a COUNT of claim records or SUM of claim amounts? - Both have their value by initially just COUNT
- Date field in Claims: What's the name of your date field in the Claims table (ClaimDate, IncidentDate, etc.)? Incident date
- rohit1991Super User
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.
- Freece4802Frequent Visitor
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,
- rohit1991Super 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.
- AnonymousNot applicable
Hi Freece4802,
If the issue still persists, we kindly request you to share the sample data in a workable format such as text, an Excel file, or a PBIX file with sample data instead of screenshots. This will enable us to assist you more effectively.
Thanks & Regards,
Prasanna Kumar
- AnonymousNot applicable
Hi Freece4802,
we kindly request you to share the sample data in a workable format such as text, an Excel file, or a PBIX file with sample data instead of screenshots. This will enable us to assist you more effectively.
Thanks & Regards,
Prasanna Kumar
- AnonymousNot applicable
Hi Freece4802,
kindly request you to share the sample data in a workable format such as text, an Excel file, or a PBIX file with sample data instead of screenshots. This will enable us to assist you more effectively.
Thanks & Regards,
Prasanna Kumar
- Freece4802Frequent Visitor
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