Forum Discussion
Extract data per ID form different table
- 1 year ago
Hi @ZanneMari , Please let us know if your issue is solved. If it is, consider marking the answer that helped 'Accept as Solution', so others with similar queries can find it easily. If not, please share the details.
Thank you.
You can create a calculated column in the Open PO table to check if the PO line item exists in the History PO table.
HasHistory = IF(
COUNTROWS(
FILTER(
HistoryPO,
HistoryPO[PO Number] = OpenPO[PO Number] &&
HistoryPO[Item ID] = OpenPO[Item ID]
)
) > 0,
TRUE,
FALSE
)
Create a calculated column to determine the latest state for each PO line item.
LatestState =
VAR CurrentStates =
FILTER(
HistoryPO,
HistoryPO[PO Number] = OpenPO[PO Number] &&
HistoryPO[Item ID] = OpenPO[Item ID]
)
VAR MaxState =
MAXX(CurrentStates, SWITCH(HistoryPO[State], "E", 1, "D", 2, "Q", 3))
RETURN
SWITCH(MaxState, 1, "E", 2, "D", 3, "Q", BLANK())
Create a measure to sum the values for the latest state without duplicates.
dax
SumLatestStateValue =
VAR LatestState = [LatestState]
VAR UniqueValues =
SUMX(
FILTER(
DISTINCT(
SELECTCOLUMNS(
HistoryPO,
"PO Number", HistoryPO[PO Number],
"Item ID", HistoryPO[Item ID],
"State", HistoryPO[State],
"Value", HistoryPO[Value]
)
),
[PO Number] = OpenPO[PO Number] &&
[Item ID] = OpenPO[Item ID] &&
[State] = LatestState
),
[Value]
)
RETURN
IF([HasHistory], UniqueValues, BLANK())
Finally, create a calculated column to calculate the spend left.
SpendLeft = OpenPO[Net Value] - [SumLatestStateValue]
Thank you so much for your help Bhanu.