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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi,
I have a work order table looking like this:
Work order ID | Installation site ID | Work order type | Work order date |
Workorder 1 | Site A | Installation | 2020-01-01 |
Workorder 2 | Site B | Installation | 2020-01-01 |
Workorder 3 | Site C | Installation | 2020-01-01 |
Workorder 4 | Site A | Inspection | 2020-01-02 |
Workorder 5 | Site B | Inspection | 2020-01-02 |
Workorder 6 | Site A | Inspection | 2020-01-05 |
Workorder 7 | Site A | Installation | 2020-01-05 |
I am looking to find a calculated column that for all work order types "Inspections" to return the latest "Installation" work order ID such as:
Work order ID | Installation site ID | Work order type | Work order date | Inspected Workorder |
Workorder 1 | Site A | Installation | 2020-01-01 | |
Workorder 2 | Site B | Installation | 2020-01-01 | |
Workorder 3 | Site C | Installation | 2020-01-01 | |
Workorder 4 | Site A | Inspection | 2020-01-02 | Workorder 1 |
Workorder 5 | Site B | Inspection | 2020-01-02 | Workorder 2 |
Workorder 6 | Site A | Inspection | 2020-01-05 | Workorder 1 |
Workorder 7 | Site A | Installation | 2020-01-05 |
I am struggling in finding a good solution. Note that multiple work orders can be found on the same installation site and also multiple inspections on the same site.
Any good pointers/tips?
Solved! Go to Solution.
[Installation Workorder] = // calculated column
if( T[Work order type] = "inspection",
// Find the most recent workorder
// for the same site where order type
// is equal to "installation". This will
// work OK only on condition that the
// workorders can be unambiguously ordered
// on the time axis.
// Bear in mind that T[Work order date]
// must be of the datetime/date type, not
// a string.
var __currentOrderDate = T[Work order date]
var __currentSite = T[Installation site]
var __potentialWorkorders =
topn(1,
filter(
T,
T[Installation site] = __currentSite
&&
T[Work order type] = "installation"
&&
T[Work order date] < __currentOrderDate
),
T[Work order date],
DESC
)
var __error =
// Either there must be one order for the
// above conditions or no such order. If
// there is more than 1 such order, it's
// an error condition. It might also be
// that if there's no such order it's an
// error condition. Then you have to change
// this logical condition to suit your needs.
// Bear in mind that you can also raise an
// error with the ERROR() function if you
// wish.
COUNTROWS( __potentialWorkorders ) > 1
var __workorder =
if( not __error,
MAXX(
__potentialWorkorders,
T[Work order ID]
),
"not possible to determine"
)
return
__workorder
)
Works like a charm, thanks for the quick reply and awesome dax!
[Installation Workorder] = // calculated column
if( T[Work order type] = "inspection",
// Find the most recent workorder
// for the same site where order type
// is equal to "installation". This will
// work OK only on condition that the
// workorders can be unambiguously ordered
// on the time axis.
// Bear in mind that T[Work order date]
// must be of the datetime/date type, not
// a string.
var __currentOrderDate = T[Work order date]
var __currentSite = T[Installation site]
var __potentialWorkorders =
topn(1,
filter(
T,
T[Installation site] = __currentSite
&&
T[Work order type] = "installation"
&&
T[Work order date] < __currentOrderDate
),
T[Work order date],
DESC
)
var __error =
// Either there must be one order for the
// above conditions or no such order. If
// there is more than 1 such order, it's
// an error condition. It might also be
// that if there's no such order it's an
// error condition. Then you have to change
// this logical condition to suit your needs.
// Bear in mind that you can also raise an
// error with the ERROR() function if you
// wish.
COUNTROWS( __potentialWorkorders ) > 1
var __workorder =
if( not __error,
MAXX(
__potentialWorkorders,
T[Work order ID]
),
"not possible to determine"
)
return
__workorder
)
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
7 | |
5 | |
4 | |
3 |
User | Count |
---|---|
12 | |
11 | |
10 | |
9 | |
8 |