Forum Discussion
thollitez
8 years agoRegular Visitor
Need help SUM or AVERAGE last 7 Previous Records (Not Using Date)
Hi Guys, I've been checking the forum and google regarding SUM or AVERAGE last specific number of records. All solutions i've found is using DATE, but DATE is irrelevant on what i am trying to a...
- 8 years ago
Hi thollitez,
For your scenario, you should create an index column in Query Editor and create the measure below.
1. Create Index column
2. Create the measure under Modeling tab.
Moving Average last 7 Records = VAR SevenrecordsTotal = CALCULATE ( SUM ( 'table'[UNITS SOLD] ), FILTER ( ALL ( 'table'[Index] ), 'table'[Index] <= MAX ( 'table'[Index] ) && 'table'[Index] >= MAX ( 'table'[Index] ) - 6 ), ALL ( 'table' ) ) VAR Records = CALCULATE ( DISTINCTCOUNT ( 'table'[Index] ), FILTER ( ALL ( 'table'[Index] ), 'table'[Index] <= MAX ( 'table'[Index] ) && 'table'[Index] >= MAX ( 'table'[Index] ) - 6 && 'table'[Index] <> BLANK () ), ALL ( 'table' ) ) RETURN IF ( SUM ( 'table'[Index] ) >= 7, DIVIDE ( SevenrecordsTotal, Records ), BLANK () )Then you could get the output below.
You also could refer to the attached pbix
Best Regards,
Cherry
v-piga-msft
Resident Rockstar
8 years agoHi thollitez,
For your scenario, you should create an index column in Query Editor and create the measure below.
1. Create Index column
2. Create the measure under Modeling tab.
Moving Average last 7 Records =
VAR SevenrecordsTotal =
CALCULATE (
SUM ( 'table'[UNITS SOLD] ),
FILTER (
ALL ( 'table'[Index] ),
'table'[Index] <= MAX ( 'table'[Index] )
&& 'table'[Index]
>= MAX ( 'table'[Index] ) - 6
),
ALL ( 'table' )
)
VAR Records =
CALCULATE (
DISTINCTCOUNT ( 'table'[Index] ),
FILTER (
ALL ( 'table'[Index] ),
'table'[Index] <= MAX ( 'table'[Index] )
&& 'table'[Index]
>= MAX ( 'table'[Index] ) - 6
&& 'table'[Index] <> BLANK ()
),
ALL ( 'table' )
)
RETURN
IF ( SUM ( 'table'[Index] ) >= 7, DIVIDE ( SevenrecordsTotal, Records ), BLANK () )
Then you could get the output below.
You also could refer to the attached pbix
Best Regards,
Cherry
- thollitez8 years agoRegular Visitor
Thank you very much sir v-piga-msft, it really solved my problem.
You're the best.
- v-piga-msft8 years ago
Resident Rockstar