Anu
October 17, 2020, 3:51am
1
In the AdjProvStock LM column , i would like to get the previous month AdjProvStock as a calculated column.

To get it as a measure, this formula is enough
AdjProvStockLM = CALCULATE(SUM(Funding[AdjProvStock]),PARALLELPERIOD(‘Date’[Date],-1,MONTH))

But how to get it as a calculated column, I Understand it can be done using earlier function, but how exactly should it be done.Fund.pbix (172.0 KB)

BrianJ
October 17, 2020, 6:29am
2
@Anu ,

Here’s how I would do it using EARLIER. First add an index column to your table, then use this for your calculated column.

```
AdjProvStock LM =
VAR PrevDate =
CALCULATE(
MAX( Funding[Date] ),
FILTER(
ALL( Funding ),
Funding[Index] < EARLIER( Funding[Index] )
)
)
VAR Result =
CALCULATE(
MAX( Funding[AdjProvStock] ),
FILTER(
ALL( Funding ),
Funding[Date] = PrevDate
)
)
RETURN Result
```

@Greg has put together an awesome summary of all the common previous row value patterns here in the link below. It’s got an alternative approach using variables to capture the prior row context instead of EARLIER that is now the generally recommended approach:

https://forum.enterprisedna.co/t/previous-row-value/9789https://forum.enterprisedna.co/t/previous-row-value/9789

I hope this is helpful. Full solution file attached below.

2 Likes

Anu
October 17, 2020, 6:33am
3
Could you please attach the the pbix also

BrianJ
October 17, 2020, 6:39am
4
Sure – solution file now attached above.

1 Like