Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hey,
So I wanted to get the 2nd latest/last value of a column, say for example:
| ID | Name | Value |
| 1 | Test1 | 0 |
| 2 | Test2 | 69 |
| 3 | Test3 | 42 |
in this scenario, I need to get the 2nd to the last row which is 69.
how can i get this in a measure or column?
Thanks yall, much appreciated.
Solved! Go to Solution.
Hi @EvanGetsItDone ,
You can create a measure as below to get it, please find the details in the attachment.
2nd latest value =
VAR _maxid =
CALCULATE ( MAX ( 'Table'[ID] ), ALLSELECTED ( 'Table' ) )
VAR _secondmid =
CALCULATE (
MAX ( 'Table'[ID] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[ID] < _maxid )
)
RETURN
CALCULATE (
MAX ( 'Table'[Value] ),
FILTER ( 'Table', 'Table'[ID] = _secondmid )
)
Best Regards
Hi @EvanGetsItDone ,
You can create a measure as below to get it, please find the details in the attachment.
2nd latest value =
VAR _maxid =
CALCULATE ( MAX ( 'Table'[ID] ), ALLSELECTED ( 'Table' ) )
VAR _secondmid =
CALCULATE (
MAX ( 'Table'[ID] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[ID] < _maxid )
)
RETURN
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( 'Table', 'Table'[ID] = _secondmid )
)
Best Regards
Hello @EvanGetsItDone ,
try the following
2nd Last Value = CALCULATE(MAX('Table'[Value]),'Table'[ID] = MAX('Table'[ID])-1)
Proud to be a Super User! | |
Hello Thanks!
Would this be possible for a text? let's say, the values are:
| ID | Name | Value |
| 1 | Test1 | a |
| 2 | Test2 | b |
| 3 | Test3 | c |
I would like to get the b, which is the 2nd last value, but it is a text.
Thanks!
Hi,
Does second last have to be determined based on numbers being in the ID column?
Hi,
Does second last have to be determined based on numbers being in the ID column?
Hi @EvanGetsItDone ,
You can create a measure as below to get it, please find the details in the attachment.
2nd latest value =
VAR _maxid =
CALCULATE ( MAX ( 'Table'[ID] ), ALLSELECTED ( 'Table' ) )
VAR _secondmid =
CALCULATE (
MAX ( 'Table'[ID] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[ID] < _maxid )
)
RETURN
CALCULATE (
MAX ( 'Table'[Value] ),
FILTER ( 'Table', 'Table'[ID] = _secondmid )
)
Best Regards
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 51 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 64 | |
| 39 | |
| 33 | |
| 23 |