Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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 AAA+) that can change at irregular intervals (so not monthly or yearly).
I have a table that shows the latest rating for countries that have had it changed in the past 3 months:
Now I want to get another column in this table that shows the what the previous rating was, thus my need to find the 2nd to last value.
All the columns in the table are normal raw data columns (no measures).
Anyone know how I can do this?
Thanks,
Raj
Solved! Go to Solution.
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
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 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!!
Hi,
Share the link from where i can download the PBI file or paste the Table here so that i can take it to an Excel file. More importantly, please show the expected result in another column.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 132 | |
| 88 | |
| 82 | |
| 68 | |
| 64 |