;WITH cteHist AS (
    SELECT [ibs].[database_name], [ibs].[backup_start_date], [ibs].[backup_finish_date], ROW_NUMBER()OVER(PARTITION BY [ibs].[database_name] ORDER BY [ibs].[backup_finish_date] DESC ) AS rnk
    FROM msdb.dbo.backupset ibs 
    WHERE [ibs].[type]='D'
)
, ctehistFilt AS (
SELECT *
FROM [cteHist]
--WHERE [cteHist].[rnk] <= 10
WHERE [cteHist].[backup_finish_date] >= DATEADD(DAY, -7, CURRENT_TIMESTAMP)
)

SELECT 
    d.name
    --,[last 5 backups] = STUFF(CONVERT(VARCHAR(MAX),bkp.strDates),1,1,'')
    ,h.[backup_finish_date]
    ,h.[rnk] AS position
    ,d.collation_name
    ,d.compatibility_level
FROM sys.databases d
    JOIN [ctehistFilt] h ON h.[database_name] = d.[name]
WHERE 1=1
and rnk = 1
AND d.name NOT IN (
    'master'
    ,'model'
    ,'tempdb'
    ,'msdb'
)
