Forum Discussion

legrand's avatar
legrand
Icon for Helper I rankHelper I
8 years ago
Solved

Average stock through movements

Hi, after reading hours of other threads and not coming to a conclusion I have to open yet another inventory thread.   I got a table with stock movements :   04.10.2017 56. 09.10.2017 34...
  • Phil_Seamark's avatar
    Phil_Seamark
    8 years ago

    HI legrand

     

    I think this is getting pretty close to your spreadsheet.

     

    I created a new calculated table that I could add missing dates and apply a running total to.

     

    New Table = 
    VAR Date1 = GENERATE(CALENDAR(DATE(2017,10,1),DATE(2017,12,1)),VALUES('Table1'[Article]))
    VAR Step1 = SUMMARIZECOLUMNS('Table1'[Article],'Table1'[Date],"Q",SUM(Table1[Quantity]))
    VAR Step2 = NATURALLEFTOUTERJOIN(SELECTCOLUMNS(Date1,"Date",[Date]+0,"Article",[Article]),SELECTCOLUMNS(Step1,"Date",[Date]+0,"Article",[Article],"Quantity",[Q]))
    RETURN  ADDCOLUMNS(Step2,"Column to Average",VAR s = CALCULATE(SUM('Table1'[Quantity]),FILTER('Table1',[Date]<=EARLIER([Date]) && [Article] = EARLIER([Article])))return if(s=BLANK(),0,s))

    This gave me a column that I could easily average using a visual

    .

     

    Here is a link to a PBIX file that contains your data, my code and the visual

     

    https://1drv.ms/u/s!AtDlC2rep7a-oX7_Ag9RNSNZVZnA