Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Show the text value of a column based on the max of another


I have a dataset where each entry is a book register. One of the columns is the title and, among others, there is a column for the publishing year. I want to create a measure/card that shows the name of the newest and oldest.

I've used:

Oldest = 
VAR old = MIN('Livros DB'[year])
RETURN
CALCULATE (
    VALUES ( 'Livros DB'[Title] ),
    FILTER ( ALL ( 'Livros DB'[year] ), 'Livros DB'[year] = old )
)

And this works for the oldest. However, it only works because there is only one entry with the same year. When I use the same solution for the newest, it fails, because there is more than just one entry for the same year. How could I return a list of the newest books?


Solution

  • Newest = 
    VAR new = MAX('Livros DB'[year])
    RETURN
        CALCULATE (
            CONCATENATEX( VALUES ( 'Livros DB'[Title] ), 'Livros DB'[Title], ","),
            FILTER ( ALL ( 'Livros DB'[year] ), 'Livros DB'[year] = new )
        )