Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PeterL1
Helper I
Helper I

Rolling Average Invoice Cost Based on Number of Invoices

Hi, 

 

I'm struggling to find an answer to an issue that i have.

I am trying to get out the last 5 invoices by supplier down to an itemised level (by date), to calculate an average cost on the item for those last 5 invoices.

The Invoice dates ranks back to 2009, but i cannot just take invoices from say this year as i might not have bought something for 18 months etc.

I've also attached a link to some more Data.

https://www.dropbox.com/l/scl/AACHeYibKkWAnRxJTe5cW6aiJPgsZLUr6Dc

 

This is the Data i have:

 Capture.PNG

 

 

This is the data i would like, by supplier and by item within that supplier.

 

Capture2.PNG

Any help on this would be appreciated.

Thanks

Peter

1 ACCEPTED SOLUTION

@PeterL1

 

Try this MEASURE

 

Sum Value =
CALCULATE (
    SUM ( TableName[NET_VALUE] ),
    TOPN ( 5, TableName, TableName[INVOICE DATE], DESC )
)

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @PeterL1,

 

I cant access to sharing file, I think you need to check the settings.

 

You can follow below steps to if they suitable for your requirement:

1. Create table visual.

2. Add 'Supplier Id' and 'Item ID' column to table visual as group columns.

3. Add QTY and 'NET_VALUE' columns to visual with summary mode 'SUM'.

4. Write a measure to get average and drag to table visual.

AVERAGE =
DIVIDE ( SUM ( Table['NET_VALUE'] ), SUM ( TABLE[QTY] ), 0 )

 

If above not help, please share sample data for test.

 

Regards,

Xiaoxin Sheng

Hi @Anonymous

 

https://www.dropbox.com/s/t0hm8itfxd3bajf/Table1.xlsx?dl=0

 

I've attached another link, hopefully this one will work.

 

The calculation that you have written are fine for all the invoices, however i only want the last 5 invoices relating to each supplier and to ignore any previous invoice in the calculation (which is where i am struggling).

 

Thanks

Peter

 

 

 

 

@PeterL1

 

Try this MEASURE

 

Sum Value =
CALCULATE (
    SUM ( TableName[NET_VALUE] ),
    TOPN ( 5, TableName, TableName[INVOICE DATE], DESC )
)

Hi @Zubair_Muhammad

 

Thats it !

 

Thanks for the quick reply

 

Peter

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.