Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 36
Default Summing based on criteria and instance number

Greetings,
I have a sheet with data that includes Vehicle, Milage, Cost, etc. What I'm
trying to do is find a formula that will allow me to, for example, sum the
cost of the last 4 entries for vehicle 1. Changing the sort order of the
data is, unfortunately, not an option.
There are a number of ways that I can sum all of the entries for vehicle 1,
(assume named ranges for vehicle and cost columns):

Sumif(vehicle,"v1",cost)
Sumproduct(--(vehicle = "v1"),cost)
{Sum(If(vehicle="v1",cost,0))}

I just can't seem to figure out a way to add the criteria of only going to 4
instances. It can be done with a UDF, but I like to avoid that as much as
possible, as they tend to be much slower than built in functions (or, at
least they are when I write them).

Any suggestions that anyone has would be greatly appreciated.
--
Mike Lee
McKinney,TX USA
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,726
Default Summing based on criteria and instance number

=SUM(N(OFFSET(cost,LARGE(IF(vehicle="v1",ROW(cost) ),{1,2,3,4})-MIN(ROW(cost)),0)))

it is an array formula, so commit with Ctrl-Shift-Enter, not just Enter

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"mikelee101" <mikelee101athotmaildotcom wrote in message
...
Greetings,
I have a sheet with data that includes Vehicle, Milage, Cost, etc. What
I'm
trying to do is find a formula that will allow me to, for example, sum the
cost of the last 4 entries for vehicle 1. Changing the sort order of the
data is, unfortunately, not an option.
There are a number of ways that I can sum all of the entries for vehicle
1,
(assume named ranges for vehicle and cost columns):

Sumif(vehicle,"v1",cost)
Sumproduct(--(vehicle = "v1"),cost)
{Sum(If(vehicle="v1",cost,0))}

I just can't seem to figure out a way to add the criteria of only going to
4
instances. It can be done with a UDF, but I like to avoid that as much as
possible, as they tend to be much slower than built in functions (or, at
least they are when I write them).

Any suggestions that anyone has would be greatly appreciated.
--
Mike Lee
McKinney,TX USA



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 36
Default Summing based on criteria and instance number

Bob,
Works like a charm. I still don't know that I understand exactly what it's
doing (I'm not familiar with the "N()" function), but hopefully I can use
help and formula auditing and it'll make more sense.

Thanks again for the help.
--
Mike Lee
McKinney,TX USA


"Bob Phillips" wrote:

=SUM(N(OFFSET(cost,LARGE(IF(vehicle="v1",ROW(cost) ),{1,2,3,4})-MIN(ROW(cost)),0)))

it is an array formula, so commit with Ctrl-Shift-Enter, not just Enter

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"mikelee101" <mikelee101athotmaildotcom wrote in message
...
Greetings,
I have a sheet with data that includes Vehicle, Milage, Cost, etc. What
I'm
trying to do is find a formula that will allow me to, for example, sum the
cost of the last 4 entries for vehicle 1. Changing the sort order of the
data is, unfortunately, not an option.
There are a number of ways that I can sum all of the entries for vehicle
1,
(assume named ranges for vehicle and cost columns):

Sumif(vehicle,"v1",cost)
Sumproduct(--(vehicle = "v1"),cost)
{Sum(If(vehicle="v1",cost,0))}

I just can't seem to figure out a way to add the criteria of only going to
4
instances. It can be done with a UDF, but I like to avoid that as much as
possible, as they tend to be much slower than built in functions (or, at
least they are when I write them).

Any suggestions that anyone has would be greatly appreciated.
--
Mike Lee
McKinney,TX USA




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate average based on date and other criteria Kycajun Excel Discussion (Misc queries) 3 July 14th 06 10:08 PM
Summing quantities based on like criteria? aburnce Excel Discussion (Misc queries) 5 May 4th 06 12:11 AM
Identifying First Instance of a Value Given a Criteria carl Excel Worksheet Functions 2 April 10th 06 07:24 PM
Total Summed Count of Numeric Repeat (Paired /Double Instance) Criteria Sam via OfficeKB.com Excel Worksheet Functions 2 March 20th 06 02:29 AM
Locate a cell, based on a criteria, then use the 'Cell' command... cdavidson Excel Discussion (Misc queries) 1 November 17th 05 06:30 PM


All times are GMT +1. The time now is 03:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"