Forum Discussion
Average stock through movements
- 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
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
Hi Phil,
many thanks, didn't have time to test your solution until now...
I tried to transfer your solution to my data but I'm running into a potential error resulting in showing the same strange value in all rows. Maybe you can spot the mistake!
Best
Henry