Forum Discussion

mail2vjj's avatar
mail2vjj
Helper III
8 years ago
Solved

Closing Stock Calculation

Hello,

I have the following 2 tables. First one is Inward and second one is Outward.

 

Inward   
DateSizeTypeQuantity
01-01-1810x10A100
01-01-1820x20B100
01-01-1830x30A100
02-01-1810X10B200
03-01-1810x10A50
03-01-1830x30A50

 

 

Outward   
DateSizeTypeQuantity
01-01-1810x10A20
01-01-1820x20B30
01-01-1830x30A70
02-01-1810x10A50
02-01-1810x10A20
02-01-1820x20B50
03-01-1810x10A20
03-01-1810x10B50
03-01-1810x10B30
03-01-1830x30A70

 

I am trying to get this third table as a result, which is my Closing stock for each date by size and type both.

Closing   
DateSizeTypeQuantity
01-01-1810x10A80
01-01-1820x20B70
01-01-1830x30A30
02-01-1810x10A10
02-01-1820x20B20
02-01-1830x30A30
02-01-1810x10B200
03-01-1810x10A40
03-01-1810x10B120
03-01-1830x30A10
03-01-1820x20B20

 

I am calculating my closing stock by FIFO method.

For Example to calculate closing stock for 03-01-2018:

DateSizeTypeQuantity 
02-01-1810x10A10(+) Previous Date Closing Stock
03-01-1810x10A50(+) Purchase
03-01-1810x10A20(-) Sale
03-01-1810x10A40(=) Current Closing Stock

 

I want to create a table that will take into consideration the size and type and then give me a closing stock as a new table.

 

I dont mind if it works as a measure, or a query.

 

If anyone can help me out with this, it would be great.

 

If you need any other information or if you need any further clarification on my problem, then please let me know.

 

Thank you,

 

Vishesh Jain

  • mail2vjj's avatar
    mail2vjj
    8 years ago

    Zubair_Muhammad

     

    Thanks again for taking the time to help me out.

     

    I have updated my file to get the closing stock after taking into consideration the last date for every month, all thanks to your help. I have created a new measure 'On Hand Quantity' in the 'Final Table'.

    Here is the link:

    https://1drv.ms/f/s!Ap0qSKP-4qpThCGX0VuaSk-I9cxx

     

    Now I am trying to get the prices in my closing stock table, so that all my closing stock can be bifurcated.

     

    I would really like to know from where have you learned how to code DAX cause you are so quick with your solutions and they work!

     

    I have been spending hours an hours and not getting any results. If you could please tell me if there is any book that I can use to learn how to code in DAX.

     

    Again a huge thanks for all your help.

     

    Vishesh Jain

18 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    mail2vjj

     

    Try this

     

    First Create a CombinedTable. From the Modelling Tab>>NEW TABLE

     

    CombinedTable =
    UNION (
        SUMMARIZE (
            Inward,
            Inward[Date],
            Inward[Size],
            Inward[Type],
            "Quantity", SUM ( Inward[Quantity] )
        ),
        SUMMARIZE (
            Outward,
            Outward[Date],
            Outward[Size],
            OUTward[Type],
            "Quantity", - SUM ( oUTward[Quantity] )
        )
    )

     

     

    • Zubair_Muhammad's avatar
      Zubair_Muhammad
      Community Champion

      mail2vjj

       

      Then add this MEASURE in this new Table

       

      Closing_Stock =
      CALCULATE (
          SUM ( CombinedTable[Quantity] ),
          FILTER (
              ALLEXCEPT ( CombinedTable, CombinedTable[Size], CombinedTable[Type] ),
              CombinedTable[Date] <= SELECTEDVALUE ( CombinedTable[Date] )
          )
      )