Forum Discussion
Flag the date one before the maximum for each reference in a table
Hi,
I have a table of references which have 10 rows per reference with different dates. I needed to flag "1" in anew column for each maximum date within the 10 rows for each reference. I did this using below:
Ref1 02/02/2021 0 2
Ref1 03/02/2021 1 0
Ref2 04/02/2021 0 0
Ref2 05/02/2021 0 2
Ref2 06/02/2021 1 0
Ref3 07/02/2021 0 0
Ref3 08/02/2021 0 2
Ref3 09/02/2021 1 0
Hi DavidWaters ,
I adapted accordingly:Max Flag = VAR _maxDate = CALCULATE ( MAX ('Table'[Date] ), ALLEXCEPT ('Table','Table'[Reference] ) ) RETURN IF ( 'Table'[Date] = _maxDate, 1, 0)Second Max Flag = VAR _maxDate = CALCULATE ( MAX ('Table'[Date] ), ALLEXCEPT ('Table','Table'[Reference] ) ) VAR _secondMaxDate = CALCULATE ( MAX ('Table'[Date] ), ALLEXCEPT( 'Table','Table'[Reference] ), 'Table'[Date] < _maxDate ) RETURN IF ( 'Table'[Date] = _secondMaxDate, 2, 0 )Does it work now?
/Tom
https://www.instagram.com/tackytechtom
6 Replies
- tackytechtom
Most Valuable Professional
Hi DavidWaters ,
I got this result....
... by using the following code to create two calculated columns:
Max Flag = VAR _maxDate = MAX ('Table'[Date] ) RETURN IF ( 'Table'[Date] = _maxDate, 1, 0)Second Max Flag = VAR _maxDate = CALCULATE ( MAX ('Table'[Date] ), ALLSELECTED( 'Table' ) ) VAR _secondMaxDate = CALCULATE ( MAX ('Table'[Date] ),ALLSELECTED( 'Table' ), 'Table'[Date] < _maxDate ) RETURN IF ( 'Table'[Date] = _secondMaxDate, 2, 0 )Did that solve your issue? 🙂
/Tom
https://www.instagram.com/tackytechtom
- DavidWaters
Helper I
Hi tackytechtom
Sorry, it needs to work per reference as below - I didn't add enough example data. It has to work per reference, I think your solution does not take this into account? My mistake for not providing a full example. Can you adapt your solution to make it work against each reference please?
Ref1 01/02/2021 0 0
Ref1 02/02/2021 0 2
Ref1 03/02/2021 1 0
Ref2 04/02/2021 0 0
Ref2 05/02/2021 0 2
Ref2 06/02/2021 1 0
Ref3 07/02/2021 0 0
Ref3 08/02/2021 0 2
Ref3 09/02/2021 1 0- tackytechtom
Most Valuable Professional
Hi DavidWaters ,
I adapted accordingly:Max Flag = VAR _maxDate = CALCULATE ( MAX ('Table'[Date] ), ALLEXCEPT ('Table','Table'[Reference] ) ) RETURN IF ( 'Table'[Date] = _maxDate, 1, 0)Second Max Flag = VAR _maxDate = CALCULATE ( MAX ('Table'[Date] ), ALLEXCEPT ('Table','Table'[Reference] ) ) VAR _secondMaxDate = CALCULATE ( MAX ('Table'[Date] ), ALLEXCEPT( 'Table','Table'[Reference] ), 'Table'[Date] < _maxDate ) RETURN IF ( 'Table'[Date] = _secondMaxDate, 2, 0 )Does it work now?
/Tom
https://www.instagram.com/tackytechtom
- DavidWaters
Helper I
I used Maxx to get per reference level, but can't figure out how to flag the second max date!