Dataset I'm working with:
The index column is created by:
- Referencing this Transaction Dataset in PowerQuery
- Removing all other columns except the date column
- Removing duplicates
- and then indexing it in a separate table so that it looks like this in a separate table: IndexDataset
Within the Transaction Dataset within the Model view, I've created a column named Index and used: Index = RELATED('Index'[Index]) so now that the TransactionDataset includes an index.
Objective
I'd like to get the average of the NET transaction for a rolling X days: Raw Data from before + End Goal in a Power BI Visual - Should be average of the last 3 dates, not SUM in my screenshot.
What I've tried so far:
I tried using the DATESBETWEEN function but because some of the dates are missing, it would pick up 0s for those missing dates as mentioned in some other questions posted here.
I tried different variations of using the existing dates field however the average seems to be WAY off.
I tried using the Index function since it wouldn't chronologically list the unique date.
This gave me repeating values for each and every row, for example: Moving Avg Last 3 = SUMX ( FILTER ( ALL ( 'TransactionDataset' ), 'TransactionDataset'[TxnType] = "BUY" || 'TransactionDataset'[TxnType] = "SEL" ), VAR CurrentIndex = 'TransactionDataset'[Index] // Assuming 'Index' is the name of your index column RETURN CALCULATE ( AVERAGE ( 'TransactionDataset'[$ Amount)] ), FILTER ( ALL ( 'TransactionDataset' ), 'TransactionDataset'[Index] >= CurrentIndex - 2 && 'TransactionDataset'[Index] <= CurrentIndex ) ) )