Forum Discussion
scabral
Helper IV
6 years agoretrieve rows with max value within a group based on date filter
Hi, i have the following table with some sample data similar to what we have in our model: Claim Id Damage Id Location Id Seq # Reserve Date Reserve Value Reserve Status 1 99 33...
- Anonymous6 years ago
// Assumptions: // Apart from [Reserve Status] all other columns // in the fact table T should be hidden. Let's // assume that the AsOfDateSlicer table that stores // dates is DISCONNECTED from T. [Total Reserve] = var __asOfDate = SELECTEDVALUE( AsOfDateSlicer[Date] ) var __filter = CALCULATETABLE( ADDCOLUMNS( SUMMARIZE( T, T[ClaimId], T[DamageID], T[LocationID] ), "@MaxSeq", CALCULATE( MAX( T[Seq #] ) ) ), KEEPFILTERS( T[Reserve Status] = "approved" ), T[Reserve Date] <= __asOfDate ) var __result = CALCULATE( SUM( T[Reserve Value] ), treatas( __filter, T[ClaimId], T[DamageID], T[LocationID], T[Seq #] ), ALL( T ) ) RETURN __result
scabral
Helper IV
6 years agoHi Daxer,
this seems to work, but why did you use the KEEPFILTERS on only the Reserve Status field?
Scott
Anonymous
6 years agoNot applicable
KEEPFILTERS lets you keep existing filters on the column instead of overwriting them. This is usually needed on a column that is exposed to the end user because when the user filters by the column you usually don't want to overwrite the filter in your measure. But whether you need KEEPFILTERS or not depends on what you want to achieve. I assumed that you wanted the measure to respond dynamically to a filter on the column mentioned under KEEPFILTERs.