Search code examples
filterssasdaxssas-tabularmeasure

Calculate last year group by ID with DAX


I have a table in SSAS Tabular Model like this

Table 1
    ID      END DATE 
    1       06/24/2016  
    1       06/24/2017  
    1       06/24/2018  
    2       08/08/2017  
    2       08/08/2016  
    3       12/12/2015  

I would like to create a Mesure in DAX, in another related Table. The output should be this:

Table 2
ID  MAXYEAR
1    2018
1    2018
1    2018
2    2017
2    2017
3    2015

PLEASE !!! WITHOUT USING EARLIER. Because my model is very large, and can´t use this function.


Solution

    1. Create a relationship between the 2 tables, assuming that Table 2 contains unique values for ID.

    enter image description here

    1. Create a year column from end date
    Year = year([END DATE])
    
    1. After that, in Table 2 create a calculated column with the following code:
    MaxYear = CALCULATE(max('Table'[Year]))
    

    Table 2 should look like this

    enter image description here