Forum Discussion
Daily cumulative average inventory value
Hi,
I'm trying to figure out a way to re-write the following formula. The end result should be an average of the closing balance for the past 365 days.
Here is the closing balance forumla
Closing Balance:=
VAR MaxDate = MAX('Date Dimension'[Date]) RETURN
CALCULATE(
IF(ROUND(SUM([Extended Cost - Modified]);2)=0;BLANK();ROUND(SUM([Extended Cost - Modified]);2));
'Item Ledger'[Date - For G/L (and Voucher)]<= MaxDate
)
Here is a an example of what I would like to achieve, but I cant figure out the dax syntax
Average Daily Balance:=
VAR MaxDate = MAX('Date Dimension'[Date]) RETURN
VAR i = 0;
VAR total = 0;
DIVIDE(
do {
total = total + CALCULATE(
IF(
ROUND(SUM([Extended Cost - Modified]);2)=0;
BLANK();
ROUND(SUM([Extended Cost - Modified]);2));
'Item Ledger'[Date - For G/L (and Voucher)]<= MaxDate - i
)
i++
} while ( i < 365 );
365
)
How would I go about writing this?
1 Reply
- sturlawsResident Rockstar
Hi dimitrishuk,
if you include sample data in your posts, it is much easier to help you.
Without knowing your data, it becomes a bit of guesswork. Try this and see if it helps you getting what you want:Average Daily Balance = VAR _maxdate = CALCULATE ( MAX ( 'Date dimension'[date] ); ALL ( 'Date dimension' ) ) RETURN CALCULATE ( [closing balance]; FILTER ( ALL ( 'Date dimension'[date] ); 'Date dimension'[date] <= _maxdate && 'Date dimension'[date] > _maxdate - 365 ) ) / 365regards,