Forum Discussion

Akos07's avatar
Akos07
Helper I
4 years ago
Solved

Stock quantity counting help

Hi,

 

I have the following problem. My matrix countains products, currentstock at time, and current price at the time.

 

As you can see, this product started with 40 stock, and gets lower with sales. It works great. But if i add a date filter, and lets say i give it 2022.06.17 as starting date it starts counting from 0. The correct starting stock should be 37. I dont have the current stock quantity in tables, i have to calculate it from sales and delivery records.

 

 

I tried this measure but its not working.

 

VAR varDate = SELECTEDVALUE(BI_DocumentItemsView[BI_DocumentHeadersView.FulfillmentDate_Local_Date])

VAR minDate =
Calculate(
MIN(BI_DocumentItemsView[BI_DocumentHeadersView.FulfillmentDate_Local_Date]),
All(BI_DocumentItemsView)
)

VAR varProduct = SELECTEDVALUE(BI_DocumentItemsView[ProductId])

RETURN


CALCULATE(
SUM(BI_DocumentItemsView[ItemQuantityDir]),
BI_DocumentItemsView[BI_DocumentHeadersView.FulfillmentDate_Local_Date] <= varDate
&& BI_DocumentItemsView[BI_DocumentHeadersView.FulfillmentDate_Local_Date] >= minDate
&& BI_DocumentItemsView[ProductId] = varProduct,
FILTER(Movements,Movements[Stock]= TRUE())
)
 
Also if i close the product the row total aint working. 

 

 

The expected result would be the last stock quantity at the time. Starting from 40 to 28, if i close the row it should show 28 as the current stock.

 

I would like to ask for same help how to fix this problem.

 

Thank you.

  • Akos07's avatar
    Akos07
    4 years ago

    Hi, i found the solotion. In the item table for each row i created a new cumulative sum column. After that, i created a measure that gets me the max ID for each date. After that i know the row with the quantity i am looking for.

11 Replies

  • Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
    Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. Screenshots of your source data are not useful.
    Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

    https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

    • Akos07's avatar
      Akos07
      Helper I

      Hello,

       

      Thanks for the reply.

       

      Expected Outcome:

       

      At each documentheader fulfillmentdate, i would like to get the actual stock quantity, based on document movement.

       

      Filtering: 2022.01.01 - 2022.12.31

       

      2022.may 11. --> 40  --> Started at 0, but got a delivery +40

      2022.jun.2 --> 40 --> Started at 40, followed by - 20 + 20, the outcome is 40.

      2022.jun 9 --> 39 --> Started at 40, sold 1, outcome is 39

      2022.jun 10 --> 38 --> Started at 39, sold 1, outcome is 38

      2022.jun 17 --> 37 --> Started at 38, sold 1, outcome is 37

      2022.jun 24 --> 36 --> Started at 37, sold 1, outcome is 36

      2022.jun 25 --> 35 --> Started at 36, sold 1, outcome is 35

      and so on...

       

      Filtering: 2022.06.10 -  2022.06.24

       

      2022.jun 10 --> 38 --> Before 06.10 the stock is 39, sold 1, outcome is 38

      2022.jun 17 --> 37 --> Started at 38, sold 1, outcome is 37

      2022.jun 24 --> 36 --> Started at 37, sold 1, outcome is 36

       

      If i close up the matrix i should see Stock quantity 36 as this is the last value of the filtering.

       

      Relationships:

       



  • DocumentHeaderIdDocumentNumberStoreIdWarehouseIdDocumentDateFulfillmentDateNetValueGrossValueMovementIdDirectionDirectionStrMovementTypeStrPartnerIdPartnerCodePartnerNamePartnerShortName
    2BSZ22-PC-00012328.máj.2210.máj.22518624611976,3131(+)Delivery11Paul Heumann SAPaul Heumann SA
    9RKA22-100-00012302.jún.2202.jún.2227482832429718-1(-)Transfer ---
    10RKV22-100-00012202.jún.2202.jún.22274828324297191(+)Transfer ---
    117PNY22-100-00532204.aug.2204.aug.2223498,88295407-1(-)Cash Register ---
    111PNY22-100-00512202.aug.2202.aug.2210291,63126657-1(-)Cash Register ---
    91PNY22-100-00352213.júl.2213.júl.2212993,27159167-1(-)Cash Register ---
    79PNY22-100-00302207.júl.2207.júl.2210206124307-1(-)Cash Register ---
    78PNY22-100-00292206.júl.2206.júl.2210573,46129777-1(-)Cash Register ---
    68PNY22-100-00232229.jún.2229.jún.2210678,54132987-1(-)Cash Register ---
    64PNY22-100-00202225.jún.2225.jún.222525,4229807-1(-)Cash Register ---
    44PNY22-100-00132217.jún.2217.jún.2214208,73174707-1(-)Cash Register ---
    30PNY22-100-00072210.jún.2210.jún.2222485,84280987-1(-)Cash Register ---
    27PNY22-100-00062209.jún.2209.jún.2223150,33284087-1(-)Cash Register ---
    • Akos07's avatar
      Akos07
      Helper I
      DocumentHeaderIdDocumentNumberDirectionDirectionStrPartnerIdStoreIdWarehouseIdProductIdProductCodeProductNameProductTypeNameItemQuantityDirItemNetPriceItemGrossPriceItemNetValuePromoItemGrossValuePromo
      117PNY22-100-0053-1(-) 2211Heumann macesz dara (kóser) 400gNormal-21686,4419903372,883980
      10RKV22-100-00011(+) 2211Heumann macesz dara (kóser) 400gNormal2011211322,782242026455,6
      9RKA22-100-0001-1(-) 2311Heumann macesz dara (kóser) 400gNormal-2011211322,782242026455,6
      2BSZ22-PC-00011(+)12311Heumann macesz dara (kóser) 400gNormal4011211322,784484052911,2
      111PNY22-100-0051-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      91PNY22-100-0035-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      79PNY22-100-0030-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      78PNY22-100-0029-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      68PNY22-100-0023-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      64PNY22-100-0020-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      61PNY22-100-0019-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      44PNY22-100-0013-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      30PNY22-100-0007-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      27PNY22-100-0006-1(-) 2211Heumann macesz dara (kóser) 400gNormal-11686,4419901686,441990
      • lbendlin's avatar
        lbendlin
        Super User

        which of these samples is the header view and which is the item view?  Also - what is your locale?