Forum Discussion
averagex + values + filter + all
Hello guys, I need help. Come on:
I have a stock table with the following values:
1/15/2020 qty 50
01/18/2020 qty 30
I need to calculate the average, so in logic we have:
1/15/2020 qte 50
1/16/2020 qte 50 (since there was no movement, the balance is the same as the previous day)
01/17/2020 qte 50 (as there was no movement so the balance is the same as the previous day)
01/18/2020 qte 30
Then resulting in: 50 + 50 + 50 + 30 = 180, I take the total and divide it by the days (in this case 4), ending 180/4 = 45.
But I can only get the result 40:
1/15/2020 qte 50
01/18/2020 qte 30
80/2=40.
Can you help me?
Anonymous
I have modified only the measure to replace the date field. I used the same file use sent me last,
Check the file: https://1drv.ms/u/s!AmoScH5srsIYgYIbFhfhthmc42ggVw?e=1jQjGfAverage Stock = VAR _CURRENTDATE = MAX(dim_data[sk_data]) VAR _STARTDATE = MIN(dim_data[sk_data]) VAR _DATES = GENERATESERIES( _STARTDATE, _CURRENTDATE,1) VAR T1 = ADDCOLUMNS( _DATES, "QTY", VAR _CURRENTQTY = lOOKUPVALUE(f_estoquegado[qtde],f_estoquegado[sk_data],[Value]) VAR _DATEQTY = CALCULATE(MAX(f_estoquegado[sk_data]),dim_data[sk_data]<= EARLIER([Value]),ALL(f_estoquegado)) VAR _LASTQTY = CALCULATE(SUM (f_estoquegado[qtde]),dim_data[sk_data] = _DATEQTY,ALL(f_estoquegado)) RETURN IF( ISBLANK(_CURRENTQTY), _LASTQTY, _CURRENTQTY ) ) RETURN AVERAGEX( T1, [QTY] )________________________
Did I answer your question? Mark this post as a solution, this will help others!.
I accept KUDOS 🙂