Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Problem with calculating moving average stock levels

Hi all,

 

I am trying to create a measure that calculates the 1 month moving average of stock levels.

The "Voorraad (palletplaatsen)" calculates the stocklevels per date.

 

Spoiler
Voorraad (palletplaatsen) =
CALCULATE(
SUM(vw_VoorraadBeideLocaties[Palletplaatsen]);
FILTER( ALLSELECTED(DM_DATUM);
DM_DATUM[Datum] <= MAX(DM_DATUM[Datum])
)
)

Next I used the following formula to calculate the 1M moving average of stocklevels:

 

Spoiler
Voorraad (palletplaatsen) 1M MA =
AVERAGEX(
DATESINPERIOD(
DM_DATUM[Datum];
LASTDATE(DM_DATUM[Datum]);
-1; MONTH );
[Voorraad (palletplaatsen)]
)

Somehow after a month the moving average is reset to weird negative numbers. This probably has to do with the openingbalance but I am not sure how to fix this... Who can help me out?

 

 

 

  • Hi Anonymous ,

    Change your measure like so:

    Voorraad (palletplaatsen) = 
    CALCULATE(
    SUM(DM_DATUM[Palletplaatsen]),
    FILTER( ALL(DM_DATUM),
    DM_DATUM[Datum] <= MAX(DM_DATUM[Datum])
    )
    )

     

    Best Regards,
    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

5 Replies

  • Icey's avatar
    Icey
    Community Support

    Hi Anonymous ,

    Change your measure like so:

    Voorraad (palletplaatsen) = 
    CALCULATE(
    SUM(DM_DATUM[Palletplaatsen]),
    FILTER( ALL(DM_DATUM),
    DM_DATUM[Datum] <= MAX(DM_DATUM[Datum])
    )
    )

     

    Best Regards,
    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Big thanks, works!!!

       

  • Icey's avatar
    Icey
    Community Support

    Hi Anonymous ,

    I can't reproduce your issue.

    If you don't mind, please share me your PBIX file without sensitive information.

     

    Best Regards,

    Icey

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Icey ,

       

      Herebelow some sample date.

      Boekingssoort is basically the type of post in our ERP.

      Inkoop = Purchase

      Verbruik = Usage

      Verkoop = Different type of usage

      Positieve correctie = Positive stock correction

      Negatieve correctie = Negative stock correction

       

      The sum of "Palletplaatsen" (Pallets) of these 5 posts per date is the stock per day, using the following formula:

       

      Voorraad (palletplaatsen) =
      CALCULATE(
      SUM(vw_VoorraadBeideLocaties[Palletplaatsen]);
      FILTER( ALLSELECTED(DM_DATUM);
      DM_DATUM[Datum] <= MAX(DM_DATUM[Datum])
      )
      )

       

      I tried to calculate the 1M MA but it seems that after a month the voorraad resets (formula below)

       

      Voorraad (palletplaatsen) 1M MA =
      AVERAGEX(
      DATESINPERIOD(
      DM_DATUM[Datum];
      LASTDATE(DM_DATUM[Datum]);
      -1; MONTH );
      [Voorraad (palletplaatsen)]

       

      Below some sample date:

       

      Hope you can pass this to Excel:

       

      Datum Palletplaatsen Boekingssoort
      7-3-2019 26 Inkoop
      7-3-2019 798,41 Positieve correctie
      7-3-2019 -11,83 Verbruik
      7-3-2019 -0,83 Verkoop
      8-3-2019 64 Inkoop
      8-3-2019 -44,79 Verbruik
      8-3-2019 -4,44 Verkoop
      9-3-2019 -4,14 Verbruik
      9-3-2019 -1,33 Verkoop
      11-3-2019 -29,27 Verbruik
      11-3-2019 -2,67 Verkoop
      12-3-2019 20,27 Inkoop
      12-3-2019 -20,07 Verbruik
      12-3-2019 -4,52 Verkoop
      13-3-2019 36,96 Inkoop
      13-3-2019 -21,97 Verbruik
      13-3-2019 -2,09 Verkoop
      14-3-2019 2,16 Inkoop
      14-3-2019 -0,07 Negatieve correctie
      14-3-2019 1533,56 Positieve correctie
      14-3-2019 -40,77 Verbruik
      14-3-2019 -5,29 Verkoop
      15-3-2019 165,49 Inkoop
      15-3-2019 -127,8 Verbruik
      15-3-2019 -36,89 Verkoop
      16-3-2019 -5,63 Verbruik
      16-3-2019 -9,8 Verkoop
      18-3-2019 96,13 Inkoop
      18-3-2019 -86,1 Verbruik
      18-3-2019 -18,11 Verkoop
      19-3-2019 155,99 Inkoop
      19-3-2019 1,27 Positieve correctie
      19-3-2019 -80,71 Verbruik
      19-3-2019 -21,2 Verkoop
      20-3-2019 157,33 Inkoop
      20-3-2019 -83,33 Verbruik
      20-3-2019 -18,52 Verkoop
      21-3-2019 131,71 Inkoop
      21-3-2019 -134,03 Verbruik
      21-3-2019 -23,52 Verkoop
      22-3-2019 111,11 Inkoop
      22-3-2019 -115,32 Verbruik
      22-3-2019 -39,19 Verkoop
      23-3-2019 -22,64 Verbruik
      23-3-2019 -14,71 Verkoop
      24-3-2019 -6,11 Verbruik
      25-3-2019 125,99 Inkoop
      25-3-2019 -473,24 Verbruik
      25-3-2019 -21,87 Verkoop
      26-3-2019 137,38 Inkoop
      26-3-2019 -111,02 Verbruik
      26-3-2019 -31,94 Verkoop
      27-3-2019 193,41 Inkoop
      27-3-2019 -4,35 Negatieve correctie
      27-3-2019 0,02 Positieve correctie
      27-3-2019 253,68 Verbruik
      27-3-2019 -30,96 Verkoop
      28-3-2019 274,2 Inkoop
      28-3-2019 -158,47 Verbruik
      28-3-2019 -36,16 Verkoop
      29-3-2019 332,9 Inkoop
      29-3-2019 0,49 Positieve correctie
      29-3-2019 -170,5 Verbruik
      29-3-2019 -73,44 Verkoop
      30-3-2019 -31,77 Verbruik
      30-3-2019 -19,22 Verkoop
      31-3-2019 -19,09 Verbruik
      1-4-2019 114,39 Inkoop
      1-4-2019 18 Positieve correctie
      1-4-2019 -133,43 Verbruik
      1-4-2019 -43,62 Verkoop
      2-4-2019 174,43 Inkoop
      2-4-2019 -133,71 Verbruik
      2-4-2019 -37,43 Verkoop
      3-4-2019 156,81 Inkoop
      3-4-2019 -0,21 Negatieve correctie
      3-4-2019 -118,19 Verbruik
      3-4-2019 -35,27 Verkoop
      4-4-2019 193,49 Inkoop
      4-4-2019 -4,53 Negatieve correctie
      4-4-2019 6,43 Positieve correctie
      4-4-2019 -143,48 Verbruik
      4-4-2019 -65,56 Verkoop
      5-4-2019 209,95 Inkoop
      5-4-2019 -173,68 Verbruik
      5-4-2019 -40,92 Verkoop
      6-4-2019 -10,69 Verbruik
      6-4-2019 -22,9 Verkoop
      7-4-2019 -1,81 Verbruik
      8-4-2019 194,75 Inkoop
      8-4-2019 -27,37 Negatieve correctie
      8-4-2019 -145,91 Verbruik
      8-4-2019 -22,41 Verkoop
      9-4-2019 235,53 Inkoop
      9-4-2019 -125,44 Verbruik
      9-4-2019 -34,35 Verkoop
      10-4-2019 184,4 Inkoop
      10-4-2019 1,29 Positieve correctie
      10-4-2019 -142,17 Verbruik
      10-4-2019 -30,19 Verkoop
      11-4-2019 231,64 Inkoop
      11-4-2019 -176,31 Verbruik
      11-4-2019 -41,21 Verkoop
      12-4-2019 293,84 Inkoop
      12-4-2019 -2,4 Negatieve correctie
      12-4-2019 0,96 Positieve correctie
      12-4-2019 -195,69 Verbruik
      12-4-2019 -56,49 Verkoop
      13-4-2019 -91,23 Verbruik
      13-4-2019 -33,6 Verkoop
      14-4-2019 -40,45 Verbruik
      15-4-2019 175,69 Inkoop
      15-4-2019 -195,25 Verbruik
      15-4-2019 -56,92 Verkoop