Forum Discussion

MatthewUK's avatar
MatthewUK
New Member
2 years ago
Solved

How to calculate a value from one column based on another column's maximum value

I have table as shown below. For each Reference, there may be multiple rows at different dates. I want to be able to create a calculated column that will evaluate, for each Reference, the value of the Count field where the Date is the maximum for that Reference (ie not just the maximum date in the table as a whole) Is this possible?

 

ReferenceCountDate
A10601/10/2020
A8101/10/2021
B301/11/2022
B1701/11/2020
B1801/11/2023
B1501/11/2021
C1910/07/2023
C1901/11/2022
D5101/06/2021
D5801/06/2023
E201/04/2021
E201/04/2022
E2301/07/2021

 

What I am aiming for is:

ReferenceResult
A81
B18
C19
D58
E2

 

Many thanks for any help for this !

  • Hi MatthewUK ,
    You can achieve this by using:- 
    Result =
    VAR MaxDate = CALCULATE(MAX('YourTable'[Date]), ALLEXCEPT('YourTable', 'YourTable'[Reference]))
    RETURN
    CALCULATE(MAX('YourTable'[Count]), 'YourTable'[Date] = MaxDate)


    Hope this will help you.
    Thank you 

3 Replies

  •  thank you so much - I'd tried loads of answers from similar questions and failed but this has worked a treat!

  • Hi MatthewUK ,
    You can achieve this by using:- 
    Result =
    VAR MaxDate = CALCULATE(MAX('YourTable'[Date]), ALLEXCEPT('YourTable', 'YourTable'[Reference]))
    RETURN
    CALCULATE(MAX('YourTable'[Count]), 'YourTable'[Date] = MaxDate)


    Hope this will help you.
    Thank you