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 Daxar,
so another question. I tried to use the DAX to also count a column from a dimension table, but only for the rows in the dimension table that exist in the TREATAS table like this:
Count of Claims =
VAR ReserveFilter =
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE (
'Claim Reserve Values',
'Claim Reserve Values'[Claim ID],
'Claim Reserve Values'[Damage ID],
'Claim Reserve Values'[Location ID]
),
"MaxSeq", CALCULATE ( MAX ( 'Claim Reserve Values'[Reserve Sequence Num] ) )
),
KEEPFILTERS('Claim Reserve'[Reserve Status ID] = 2 )
)
VAR Result =
CALCULATE (
DISTINCTCOUNT( 'Claim Adjustment File'[Claim Number]),
TREATAS (
ReserveFilter,
'Claim Reserve Values'[Claim ID],
'Claim Reserve Values'[Damage ID],
'Claim Reserve Values'[Location ID],
'Claim Reserve Values'[Reserve Sequence Num]
),
ALL ( 'Claim Reserve Values' ),
'Claim Reserve'[Reserve Group ID] in {1000007, 1000008}
)
RETURN
Result
howerver, the count comes back for all of the rows in the 'Claim Adjustment File' table. I want to only count the 'Claim Adjustment File'[Claim Number] if it exists as part of the TREATAS result. The [claim id] field would be the relationship to use between the tables.
thansk
scott
Anonymous
6 years agoNot applicable
I don't know the model, hence I can't tell you where you could be wrong in the formula. Sorry.