I am trying to lookup a value from another table with a filter, and a TOPN.
I have two tables like this:
Table1
ID Latest
X-1
X-2
Table2 (Key is concatenation of ID and Start)
ID Start Key Status
X-1 1 X-1 - 1 Done
X-1 2 X-1 - 2 Done
X-1 3 X-1 - 3 Open
X-1 4 X-1 - 4 Open
X-2 1 X-2 - 1 Done
X-2 2 X-2 - 2 Open
X-2 3 X-2 - 3 Open
X-2 4 X-2 - 4 Open
What I'd like to do is, for the empty values in Table1[Latest]
to find the value in Table2[Key]
based off the highest number in Table2[Start]
and only those in Table2[Status]
with "Open"
respectively for each ID
in Table1
.
So that Table1 ends as:
ID Latest
X-1 X-1 - 2
X-2 X-2 - 1
I thought something along the lines of
Latest = LOOKUPVALUE(ggTwo[Key], ggTwo[ID], TOPN(1, ggTwo, CALCULATE(ALL(ggTwo[ID]), FILTER(ggTwo, ggTwo[ID] = ggOne))))
But this is refering to multiple columns. I am not sure how to tackle this one.
答案 0 :(得分:0)
要获得状态开启的最佳起点,我在表2中创建了一个计算列。
LastOpenStart =
CALCULATE (
MAX ( ggTwo[Start] ),
ggTwo[Status] = "open",
FILTER ( ggTwo, ggTwo[ID] = EARLIER ( ggTwo[ID] ) )
//Query
EVALUATE
SELECTCOLUMNS(
NATURALINNERJOIN (
FILTER ( ggTwo, ggTwo[LastOpenStart] = ggTwo[Start] ),
FILTER ( ggOne, ggOne[Latest] = BLANK () )
),
"ID",ggTwo[ID],
"Key",ggTwo[Key]
)