Forum Discussion
Inventory Average Cost
Hi Leandro,
Could you try the formula below to see if it works in your scenario? :smileyhappy:
Average Cost =
VAR currentPeriod = Table1[Period]
VAR minPeriod =
CALCULATE ( MIN ( Table1[Period] ), ALL ( Table1 ) )
RETURN
IF (
currentPeriod = minPeriod,
DIVIDE (
Table1[Incial Total Value] + Table1[Input Total Value],
Table1[Incial Quant] + Table1[Input Quant]
),
DIVIDE (
CALCULATE (
SUMX ( Table1, Table1[Incial Total Value] + Table1[Input Total Value] ),
FILTER ( ALL ( Table1 ), Table1[Period] < currentPeriod )
)
+ Table1[Input Total Value],
CALCULATE (
SUMX ( Table1, Table1[Incial Quant] + Table1[Input Quant] + Table1[Out Quant] ),
FILTER ( ALL ( Table1 ), Table1[Period] < currentPeriod )
)
+ Table1[Input Quant]
)
)
Regards
Hi v-ljerr-msft
Thanks a lot for your help, i tried the formula that you sent, but there is something that still not working, but i can see the metod is the right, setting "VAR" for the calculation to avoid circular relationships.
Maybe my description of the problem was not precise enough, so i posted the file on google drive, this way it can light the problem.
And again, thanks so much for the help, it will really make my job a lot easier.
- v-ljerr-msft9 years ago
Microsoft Employee
Hi Leandro,
After a few try, I was still not able to figure it out. :smileymad: So I did some research, then it turns out that it may be not possible to do it with DAX in this scenario, because of the circular dependency. Here is the similar thread for your reference. :smileyhappy:
Regards
- Leandro9 years ago
Advocate I
v-ljerr-msft Thanks a lot for your atention on this issue, seems like you're right, if in the future if a find some way to solve this, i'll let you know!
Thanks for your help!
Regards!- rsaldanha7 years agoFrequent Visitor
Hello Leandro!!
In meanwhile do you have you issue solved?
I have exactly the same need.
Greetings from Portugal.