Excel formula help please!
Author
Discussion

RobM77

Original Poster:

35,349 posts

266 months

Monday 5th November 2007
quotequote all
I'm a bit rusty on Excel - could anyone help me with the following?

I have two columns in a worksheet - dates and costs, and I want to be able to sum the costs between two dates, how would I do this?

Example:

Date Cost
01/04/2007 £395
21/06/2006 £295
23/08/2007 £450
10/02/2007 £395
11/11/2006 £195
23/02/2007 £450
14/04/2006 £595
21/08/2006 £235
23/06/2007 £420

I want someone to be able to input a date range "from" and "to" and have the cost between those dates. I want to be able to do this without sorting the data with respect to date - I'd like the list of dates and costs to be purely just a big wadge of data, and the results be available on a different worksheet by just banging in date ranges quickly and easily.

I know this is easier on Access, but this is only a small part of what the spreadsheet does, and I'd rather keep the whole thing in Excel.

any ideas?

Mattt

16,664 posts

250 months

Monday 5th November 2007
quotequote all

sstein

6,249 posts

286 months

Monday 5th November 2007
quotequote all
How about this, not sure if this is what you mean but I created a macro where you enter the date into the cells as shown then hit CTRL+SHFT+K and the total should go into E5.

The code is simple and you should be able to change it to suit.

http://www.speed-shot.co.uk/sum1.xls

_


Stuart

GreenV8S

31,028 posts

316 months

Monday 5th November 2007
quotequote all
I suspect that sumif() is the simplest way to do it.

plasticpig

12,932 posts

257 months

Monday 5th November 2007
quotequote all
=SUMIF(A1:A9,"<="& DATE(2006,12,31),B1:B9)-SUMIF(A1:A9,"<"&DATE(2006,1,1),B1:B9)

This appears to work. With your data column A is the data and column B is the value. The formula above sums all of 2006.


RobM77

Original Poster:

35,349 posts

266 months

Tuesday 6th November 2007
quotequote all
Thanks to everyone for their help. I've learnt a lot from all the responses. I used the SUMIF formula above in the end. I didn't know about SUMIF!

I'm going to have one mother of a formula now, as I simplified my problem for this thread biggrin

thanks again.

tigger1

8,490 posts

253 months

Tuesday 6th November 2007
quotequote all
If you need to unsimplify it, feel free to ask the question in full - I'm sure I'll be able to help.

If you're "learning" excel functions, make sure that you know how to use VLOOKUP and SUMPRODUCT aswell. Two very useful little buggers there. SUMIF and COUNTIF are useful too though.

RobM77

Original Poster:

35,349 posts

266 months

Tuesday 6th November 2007
quotequote all
tigger1 said:
If you need to unsimplify it, feel free to ask the question in full - I'm sure I'll be able to help.

If you're "learning" excel functions, make sure that you know how to use VLOOKUP and SUMPRODUCT aswell. Two very useful little buggers there. SUMIF and COUNTIF are useful too though.
Thanks, I will do! I used to be a bit of a whizz with Excel, and I taught it when I was an IT Trainer. It's amazing how quickly the knowledge goes though - I can't even remember the SUMIF function. I'm looking forward to refreshing my memory!

RobM77

Original Poster:

35,349 posts

266 months

Thursday 8th November 2007
quotequote all
Another question if you don't mind and then I'll be done smile

If I had this set of data:

A B
apples 3
pears 3
oranges 2
oranges 4
pears 3
apples 2
apples 4
oranges 1
oranges 4

There's no pattern, it's just a list of words and numbers.

How would I count how many times a given word appears with a given number? For example, "pears" appearing with a "3", or "oranges" appearing with a "4"?

COUNTIF seems to only do one range and one criteria, so I could count the oranges and the 4s, but not both together. SUMIF appears to be the same (using that would amount to the same thing, just dividing by four afterwards). VLOOKUP seems to stop once it's looked one thing up... This is so unbelievably easy to do in C++, it must be possible in Excel surely?

tigger1

8,490 posts

253 months

Thursday 8th November 2007
quotequote all
Given:

A B C
apples 3 apples3
pears 3 pears3
oranges 2 oranges2
oranges 4 oranges4
pears 3 etc etc
apples 2
apples 4
oranges 1
oranges 4

You could just use a pivot table on Columns A + B - this would give you your answer in the form: -


ColA ColB Count
Apples 2 1
3 1
4 1
Pears 3 2
Oranges 1 1
2 1
4 2



Edited by tigger1 on Thursday 8th November 11:45

RobM77

Original Poster:

35,349 posts

266 months

Thursday 8th November 2007
quotequote all
tigger1 said:
A B C
apples 3 apples3
pears 3 pears3
oranges 2 oranges2
oranges 4 oranges4
pears 3 etc etc
apples 2
apples 4
oranges 1
oranges 4

I would put into C1: -
= A1 & B1
to give whats above - and then do a pivot table based only on Column C.

In fact, you could just use a pivot table on Columns A + B - this would give you your answer in the form: -

ColA ColB Count
Apples 2 1
3 1
4 1
Pears 3 2
Oranges 1 1
2 1
4 2
Thanks very much! Maybe I was trying to be too clever there smile

What I'll do I think is just create the amalgamated column then do a COUNTIF. I don't want to use pivot tables as I'm only here for another few weeks and the spreadsheet is to be passed on to people who know nothing about Excel at all. They'll want to just bang numbers in and get my automatically generated stats out without any hassle.

PS - I don't work in a fruit factory wink

Vee

3,109 posts

266 months

Thursday 8th November 2007
quotequote all
Give the list a title.
Then select the whole list including title and pivot table it.

Drag Title from the PivotTable field list into the areas which says 'Drop Row Fields here'.
Then drag Title to where it says 'Drop Data Items here'.

Will group your list and count how many times each appears.

RobM77

Original Poster:

35,349 posts

266 months

Thursday 8th November 2007
quotequote all
Vee said:
Give the list a title.
Then select the whole list including title and pivot table it.

Drag Title from the PivotTable field list into the areas which says 'Drop Row Fields here'.
Then drag Title to where it says 'Drop Data Items here'.

Will group your list and count how many times each appears.
Thanks. I realise all this is really easy with pivot tables, but I don't want to use them. I'm creating the spreadsheet for other people to use, and those people don't understand pivot tables. I need to make the back end more complicated so the front end is simple Excel that they know and love.

FunkyGibbon

3,865 posts

296 months

Thursday 8th November 2007
quotequote all
RobM77 said:
COUNTIF seems to only do one range and one criteria, so I could count the oranges and the 4s, but not both together. SUMIF appears to be the same (using that would amount to the same thing, just dividing by four afterwards). VLOOKUP seems to stop once it's looked one thing up... This is so unbelievably easy to do in C++, it must be possible in Excel surely?
you could concatenate column A and B into say row c and do a countif on c

oranges 4 becomes oranges4 in column C

you could hide column c if you don't need to see it.

FG

tigger1

8,490 posts

253 months

Thursday 8th November 2007
quotequote all
FunkyGibbon said:
RobM77 said:
COUNTIF seems to only do one range and one criteria, so I could count the oranges and the 4s, but not both together. SUMIF appears to be the same (using that would amount to the same thing, just dividing by four afterwards). VLOOKUP seems to stop once it's looked one thing up... This is so unbelievably easy to do in C++, it must be possible in Excel surely?
you could concatenate column A and B into say row c and do a countif on c

oranges 4 becomes oranges4 in column C

you could hide column c if you don't need to see it.

FG
I suggested that originally and then edited it out as I (personally) think that's a horrible solution - although with Rob's wish to simplify the frontend...I guess this will be a reasonable way forward.

(Still messy and hurts my eyes though)

FunkyGibbon

3,865 posts

296 months

Thursday 8th November 2007
quotequote all
tigger1 said:
I suggested that originally and then edited it out as I (personally) think that's a horrible solution - although with Rob's wish to simplify the frontend...I guess this will be a reasonable way forward.

(Still messy and hurts my eyes though)
I agree horrible and messy - but it would work and keep it simple for his users.

plasticpig

12,932 posts

257 months

Thursday 8th November 2007
quotequote all
=SUM(IF((A1:A9="oranges")*(B1:B9=4),1,0))

You have to enter this as an array formula. To do this press ctr+shift+enter instead of just enter when you paste in the formula.



Edited by plasticpig on Thursday 8th November 12:30

FunkyGibbon

3,865 posts

296 months

Thursday 8th November 2007
quotequote all
plasticpig said:
=SUM(IF((A1:A9="oranges&quotwink*(B1:B9=4),1,0))
You have to enter this as an array formula. To do this press ctr+shift+enter instead of just enter when you paste in the formula.
oohhh - not played with array formulas these look interesting!



Edited by FunkyGibbon on Thursday 8th November 12:38

RobM77

Original Poster:

35,349 posts

266 months

Thursday 8th November 2007
quotequote all
plasticpig][NOWIKI said:
You have to enter this as an array formula. To do this press ctr+shift+enter instead of just enter when you paste in the formula.
Genius. Thanks smile

RobM77

Original Poster:

35,349 posts

266 months

Thursday 8th November 2007
quotequote all
Thanks for the help so far, the spreadsheet's looking great.

err... one more if that's ok! I thought that I'd be able to get this one, given what I've learnt so far on this thread, but I just can't see it.

It's the same as the first one, but a counting instead of adding formula:

01/04/2007 Fred Bloggs
21/06/2006 Jane Smith
23/08/2007 Barry Bloggs
10/02/2007 John Smith
11/11/2006 John Smith
23/02/2007 Barry Bloggs
14/04/2006 Jane Smith
21/08/2006 Barry Bloggs
23/06/2007 Mike Smith
02/04/2006 John Smith
23/04/2006 John Smith

If I wanted to count the unique names between two given dates, how would I do it?

For instance, how many times does John Smith occur between the 01/04/2006 and the 01/05/2006? (the answer's two of course).