Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 attain.
What i am really trying to attain is get the AVERAGE of last 7 records regardless of the dates.
Please see example below.
Thanks in advance.
Solved! Go to Solution.
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
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
Thank you very much sir v-piga-msft, it really solved my problem.
You're the best.
Hi @thollitez,
It's glad that we can help. You're welcome.
Best Regards,
Cherry
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |