Forum Discussion

mgiusto's avatar
mgiusto
Helper I
2 years ago
Solved

Running Total based on two values from different tables.

I have data which looks like this: The first 4 columns are in a table named [orders] The last column is in a table named [on_hand] this table also has the [org] and [code] field so it can lin...
  • talespin's avatar
    2 years ago

    hi mgiusto 

     

    Please try this

     

    Step1 : Created tables based on data shared by you, please note that I have kept all datatypes as whole number except date which is Date Datatype. I have not linked these two tables in data model.

     

     

    Step2 : 

    Create this measure.

     

    On Hand =
    VAR _SelOrg = SELECTEDVALUE(Orders[org])
    VAR _selCode = SELECTEDVALUE(Orders[code])
    VAR _SelDate = SELECTEDVALUE(Orders[Date])
    VAR _OnHandQty = SELECTCOLUMNS(FILTER(OnHand, OnHand[org] = _SelOrg && OnHand[code] = _selCode), "@OnHand", OnHand[on_hand])
    VAR _SumQty = CALCULATE( SUM(Orders[ord_qty]), REMOVEFILTERS(), SUMMARIZE(Orders, Orders[org], Orders[code]), Orders[Date] <= _SelDate)

    RETURN _OnHandQty - _SumQty