This is a bit tricky… I don’t think a query can do it. For the case you showed, the following works:
#let last-position(arr, searcher) = {
let rev-index = arr.rev().position(searcher)
if rev-index != none {
arr.len() - rev-index - 1
}
}
#show: body => {
let index = last-position(body.children, item => item.fields().at("label", default: none) == <thelabel>)
body.children.slice(index).join()
}
#metadata("something") <thelabel>
A
#metadata("something") <thelabel>
B
However this depends on inspecting content, and that can be hard to do right. if the label is instead nested in, say, an emphasis element, my solution won’t find it:
#metadata("something") <thelabel>
// ^ now this is the last match!
A
_#metadata("something") <thelabel>_
B
What’s the end goal you’re after? Maybe there’s a different way to achieve it?