Forum Discussion
ClaudioF
Helper II
1 year agoConditional and selective sum with filters
Hey guys! how you doing? Just got an insight in my dax code, i've been working on the logic of it for a while and i think im getting somewhere, but still need help. I need the code to return the ...
bhanu_gautam
Super User
1 year agoClaudioF , Try using
FinalCorrectStatus =
VAR CurrentItem = SELECTEDVALUE('DB_ORDERS'[Produto])
VAR CurrentOrderNum = SELECTEDVALUE('DB_ORDERS'[Pedido])
VAR StockAvailable =
CALCULATE(
SUM('Table Estoq'[Estoque Real]),
'Table Estoq'[Produto] = CurrentItem
)
VAR OrdersTable =
FILTER(
ALLSELECTED('DB_ORDERS'),
'DB_ORDERS'[Produto] = CurrentItem
)
VAR RunningTotal =
SUMX(
FILTER(
OrdersTable,
'DB_ORDERS'[Pedido] <= CurrentOrderNum
),
'DB_ORDERS'[Quant. Falta]
)
VAR PreviousRunningTotal =
SUMX(
FILTER(
OrdersTable,
'DB_ORDERS'[Pedido] < CurrentOrderNum
),
'DB_ORDERS'[Quant. Falta]
)
RETURN
IF(
ISBLANK(StockAvailable),
"out",
IF(
PreviousRunningTotal < StockAvailable,
IF(
RunningTotal <= StockAvailable,
"available",
"out"
),
"out"
)
)
ClaudioF
Helper II
1 year agoSorry it didnt work, the result is the same;