Forum Discussion
rajivraina
7 years agoHelper II
Need Help: Show second to last value
Hi all, I was hoping someone could help me figure out a way to show the second to last value for a certain field. For example, I have country credit ratings which are a text field (D through...
- 7 years ago
You could probably create a Calculated column like this:
Previous Rating = VAR CurrentDate = 'Table'[Date] VAR CurrentCountry = 'Table'[Country] VAR AllPreviousRatingsTable = FILTER ( 'Table', 'Table'[Country] = CurrentCountry && 'Table'[Date] < CurrentDate ) VAR PreviousRatingTable = TOPN ( 1, AllPreviousRatingsTable, 'Table'[Date], DESC ) VAR PreviousRating = MAXX ( PreviousRatingTable, 'Table'[Rating] ) RETURN PreviousRating
AkhilAshok
7 years agoSolution Sage
You could probably create a Calculated column like this:
Previous Rating =
VAR CurrentDate = 'Table'[Date]
VAR CurrentCountry = 'Table'[Country]
VAR AllPreviousRatingsTable =
FILTER (
'Table',
'Table'[Country] = CurrentCountry
&& 'Table'[Date] < CurrentDate
)
VAR PreviousRatingTable =
TOPN ( 1, AllPreviousRatingsTable, 'Table'[Date], DESC )
VAR PreviousRating =
MAXX ( PreviousRatingTable, 'Table'[Rating] )
RETURN
PreviousRatingrajivraina
7 years agoHelper II
AkhilAshok wrote:You could probably create a Calculated column like this:
Previous Rating = VAR CurrentDate = 'Table'[Date] VAR CurrentCountry = 'Table'[Country] VAR AllPreviousRatingsTable = FILTER ( 'Table', 'Table'[Country] = CurrentCountry && 'Table'[Date] < CurrentDate ) VAR PreviousRatingTable = TOPN ( 1, AllPreviousRatingsTable, 'Table'[Date], DESC ) VAR PreviousRating = MAXX ( PreviousRatingTable, 'Table'[Rating] ) RETURN PreviousRating
Thank you this worked perfectly!!