Forum Discussion
Date Slicer Filtering Issue
- 1 year ago
Thank you for your help, but the formula does not work. I will paste below the formula I think is close. The issue with this formula is it makes all End 0 if there is a matching Pol from 2019-2025 (my entire dataset). The only End's that are not turned to 0 are those that have a matching Pol from 2018 or earlier, which isn't in my dataset. Even if I set the date slicer to 2024-2025, all End's are still turned to 0 even if the matching Pol is in 2023.
Effective Net Exposure =VAR CurrentPolicyNumber = 'FactPolicyEndorsement'[PolicyNumber]VAR CurrentRecordType = 'FactPolicyEndorsement'[RecordType]VAR CurrentReceivedDate = 'FactPolicyEndorsement'[ReceivedDate]VAR PolNetExposure = 'FactPolicyEndorsement'[NetExposure]VAR MinDate = CALCULATE(MIN('FactPolicyEndorsement'[ReceivedDate]), ALLSELECTED('FactPolicyEndorsement'))VAR MaxDate = CALCULATE(MAX('FactPolicyEndorsement'[ReceivedDate]), ALLSELECTED('FactPolicyEndorsement'))VAR EndNetExposure_WithinRange =CALCULATE(SUM('FactPolicyEndorsement'[NetExposure]),FILTER('FactPolicyEndorsement','FactPolicyEndorsement'[PolicyNumber] = CurrentPolicyNumber &&'FactPolicyEndorsement'[RecordType] = "End" &&'FactPolicyEndorsement'[ReceivedDate] >= MinDate &&'FactPolicyEndorsement'[ReceivedDate] <= MaxDate))VAR EndNetExposure_OutsideRange =CALCULATE(SUM('FactPolicyEndorsement'[NetExposure]),FILTER('FactPolicyEndorsement','FactPolicyEndorsement'[PolicyNumber] = CurrentPolicyNumber &&'FactPolicyEndorsement'[RecordType] = "End" &&('FactPolicyEndorsement'[ReceivedDate] < MinDate || 'FactPolicyEndorsement'[ReceivedDate] > MaxDate)))RETURNIF(CurrentRecordType = "Pol",PolNetExposure + EndNetExposure_WithinRange,IF(CurrentRecordType = "End" &&CALCULATE(COUNTROWS('FactPolicyEndorsement'),FILTER('FactPolicyEndorsement','FactPolicyEndorsement'[PolicyNumber] = CurrentPolicyNumber &&'FactPolicyEndorsement'[RecordType] = "Pol" &&'FactPolicyEndorsement'[ReceivedDate] >= MinDate &&'FactPolicyEndorsement'[ReceivedDate] <= MaxDate)) > 0,0,'FactPolicyEndorsement'[NetExposure]))
Hi kellanbochenek,
Thanks for your clarification, the issue makes complete sense now. Your original version worked because it compared “Pol” and “End” records strictly within the same year, using YEAR() logic. However, the attempt to make this dynamic with ALLSELECTED() introduced a filtering problem: it was unintentionally considering records from outside the slicer range due to poor filter isolation.
To fix this and keep it dynamic across multiple years, here’s a new version of your measure that preserves the same year matching logic but dynamically adapts to the slicer’s selected years. Try using this Measure:
Effective Net Exposure =
VAR CurrentPolicyNumber = 'FactPolicyEndorsement'[PolicyNumber]
VAR CurrentRecordType = 'FactPolicyEndorsement'[RecordType]
VAR CurrentReceivedDate = 'FactPolicyEndorsement'[ReceivedDate]
VAR PolNetExposure = 'FactPolicyEndorsement'[NetExposure]
VAR SelectedYears =
VALUES('FactPolicyEndorsement'[ReceivedDate].[Year]) // Get selected years from slicer
VAR EndNetExposure_SameYear =
CALCULATE(
SUM('FactPolicyEndorsement'[NetExposure]),
FILTER(
ALL('FactPolicyEndorsement'),
'FactPolicyEndorsement'[PolicyNumber] = CurrentPolicyNumber &&
'FactPolicyEndorsement'[RecordType] = "End" &&
YEAR('FactPolicyEndorsement'[ReceivedDate]) IN SelectedYears
)
)
VAR HasPolInSelectedYears =
CALCULATE(
COUNTROWS('FactPolicyEndorsement'),
FILTER(
ALL('FactPolicyEndorsement'),
'FactPolicyEndorsement'[PolicyNumber] = CurrentPolicyNumber &&
'FactPolicyEndorsement'[RecordType] = "Pol" &&
YEAR('FactPolicyEndorsement'[ReceivedDate]) IN SelectedYears
)
)
RETURN
IF(
CurrentRecordType = "Pol",
PolNetExposure + EndNetExposure_SameYear,
IF(
CurrentRecordType = "End" && HasPolInSelectedYears > 0,
0,
'FactPolicyEndorsement'[NetExposure]
)
)
This version makes sure that only the 'End' rows with matching 'Pol' values in the selected year(s) are made zero. It fixes the issue for multiple years without using any hardcoding.
If my response was helpful, consider clicking "Accept as Solution" and give us "Kudos" so that other community members can find it easily. Let me know if you need any more assistance!
Thank you.
VALUES('FactPolicyEndorsement'[ReceivedDate].[Year]) // Get selected years from slicer. This line resulted in an error as ReceivedDate is formatted as MM/DD/YYYY. Please reference below the adjusted formula I attempted that you provided. This formula did not turn all "End"s into 0, so that part worked. However, it did not group the "Pol" and "End" correctly as this formula did not turn any "End" into 0, even if it had a matching "Pol" within the date slicer range. Any ideas? Thanks.