Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi all,
I need an answare for my question 😉 Looking for the way to get ItemNo for the date before the last date for ID and compare it to the last one.
So, right now my working measure to get the last ItemNo for last date for ID is looking as below (which is working good):
Last Item No=
VAR __lastVisitDate = CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[ID] ) )
RETURN
CALCULATE ( MAX ( Table1[ItemNo ), ALLEXCEPT ( Table1, Table1[ID] ), Table1[Date] = __lastVisitDate )
Below is a sample of a table with data marked on green that I want to get:
| id | date | ItemNo |
| 1 | 1/1/2021 | 100 |
| 1 | 2/1/2021 | 200 |
| 1 | 3/1/2021 | 300 |
| 2 | 1/1/2021 | 100 |
| 2 | 2/1/2021 | 200 |
| 2 | 3/1/2021 | 300 |
| 2 | 4/1/2021 | 400 |
Is it somehow possiable?
Appriciate for all your help!
Solved! Go to Solution.
Hi @Misq
please try
2nd Last Item No =
VAR IdTable =
CALCULATETABLE ( Table1, ALLEXCEPT ( Table1, Table1[ID] ) )
VAR LastTwoDatesTable =
TOPN ( 2, IdTable, Table1[Date] )
VAR SecondLastDate =
MINX ( LastTwoDatesTable, Table1[Date] )
RETURN
MAXX (
FILTER ( LastTwoDatesTable, Table1[Date] = SecondLastDate ),
Table1[ItemNo]
)
Hi @Misq
please try
2nd Last Item No =
VAR IdTable =
CALCULATETABLE ( Table1, ALLEXCEPT ( Table1, Table1[ID] ) )
VAR LastTwoDatesTable =
TOPN ( 2, IdTable, Table1[Date] )
VAR SecondLastDate =
MINX ( LastTwoDatesTable, Table1[Date] )
RETURN
MAXX (
FILTER ( LastTwoDatesTable, Table1[Date] = SecondLastDate ),
Table1[ItemNo]
)
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 133 | |
| 88 | |
| 85 | |
| 68 | |
| 64 |