Powerpivot: Retrieve max value for a group in a related table

1.9k Views Asked by At

I have 2 tables with a one-to-many relationship.

-TableGroup: table with groupletter

-TableAll: table with unique identifier, groupletter, a date

Problem: I want to get the max value of the date from TableAll into a new column in TableGroup. See below.

Question: What is the formula for column MAXdate?

TableAll:
ID |  Group  |     date                
1       A        4/01/2017
2       A        2/10/2016
3       A        2/06/2016
4       B        2/12/2016
5       B        15/12/2016
6       B        2/03/2017
7       C        5/02/2016
8       C        16/01/2016

TableGroup:
Group  |     MAXdate                
A           4/01/2017
B           2/03/2017
C           5/02/2016

The below formula doesn't work: See here

2

There are 2 best solutions below

0
On BEST ANSWER

The answer is:

CALCULATE (
    MAX ( TableAll[Date] ),
    FILTER ( TableAll, TableAll[Group] = EARLIER ( TableGroup[Group] ) )
)
1
On

Try:

CALCULATE (
    MAX ( TableAll[Date] ),
    FILTER ( TableGroup, TableGroup[Group] = EARLIER ( TableGroup[Group] ) )
)

How it works:

EARLIER ( TableGroup[Group] ) expression essentially means "current row". Filter function goes row by row over TableGroup table, filters it by current row's group, and then finds max date for that group.