Excel gurus - quick...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

Excel gurus - quick Q

24 Posts
13 Users
0 Reactions
83 Views
Posts: 2324
Full Member
Topic starter
 

Hi folks,

working through a project where i have a list of pubmed publications, and one of the fields is year of publication
I want to create a simple bar graph of number of publications per year.
Is there a way of creating that with a countif command? But i don't want to have to create multiple countif cells looking for each and every year. Is there a way that Excel will total only those years that appear in my column.

I'd like to automate as i have a number of different sheets and i need to create a bar chart for each one.

TIA
SusEpic


 
Posted : 13/06/2022 5:15 pm
Posts: 10315
Full Member
 

I think what you are looking for is called a PivotChart.  It should be able to do a count by year quite easily

for example this from about 4 mins onwards.  Set it to show 'count of year'

Excel pivot table and pivot chart - YouTube


 
Posted : 13/06/2022 5:17 pm
Posts: 12507
Free Member
 

Is there a way that Excel will total only those years that appear in my column.

yes, you can use an index and an array formula to create a list which is reduced to one instance of each year. that can form the left hand of your count table and the right column can do the lookup.

https://exceljet.net/formula/extract-unique-items-from-a-list

It took me a couple of goes to follow that link, you need to pay attention to cell references.

its works very effectively once its set up. I use it all the time to do what a pivot table probably could also do 😀


 
Posted : 13/06/2022 9:19 pm
Posts: 1318
Free Member
 

Sounds like a histogram? Does this help?

Instructions


 
Posted : 13/06/2022 9:32 pm
Posts: 12507
Free Member
 

hmm i think the desire is for each year to have a seperate count?


 
Posted : 13/06/2022 9:52 pm
Posts: 1318
Free Member
 

I want to create a simple bar graph of number of publications per year.

Sounds like a histogram. There’s a built in tool to do the counting and plotting.


 
Posted : 13/06/2022 10:15 pm
Posts: 12507
Free Member
 

My understanding a histogram uses bins to count.

Where as the OP wants a bargraph with a count of each year, but only the relevant years ie no gaps in the bar graph.

If i have misunderstood and the reluctance is only the number of lookups required is daunting then a histogram will totally do it by a long list of bins rather than a lookup I completely agree.


 
Posted : 13/06/2022 10:24 pm
Posts: 17779
Full Member
 

I'm with leffeboy on a Pivot Table then create the graph from there.


 
Posted : 13/06/2022 10:51 pm
Posts: 1070
Full Member
 

If you can copy/paste the 'year' column into a new sheet, you can then select the whole column and sort by ascending values. You can then select Subtotals... from the Data menu and you will get a dialogue that lets you select 'At each change in: year', 'Use function: count'. If you also check the 'Replace Current Subtotals' and 'Summary Below data' boxes you will get a count by year, but it still won't be formatted well to make a histogram. However, you will also have 3 groups (look on the top left of your sheet). If you click to close the second group you will be left with a nice table showing the year and total for each year from which you can plot a histogram. Hope that makes sense...


 
Posted : 13/06/2022 10:57 pm
Posts: 2324
Full Member
Topic starter
 

Thanks folks, some ideas for me to try this morning.....


 
Posted : 14/06/2022 9:08 am
Posts: 4985
Free Member
 

Pivot Table to get the count of the years then a bar chart to visualise it.


 
Posted : 14/06/2022 9:13 am
Posts: 0
Free Member
 

Isnt a pivot chart / table with a non-distinct count what you need. Might need to do a bit of prep to get to just the year, should work though.


 
Posted : 14/06/2022 9:17 am
Posts: 6856
Free Member
 

Quick and dirty way I'd do it:

If the dates of each article are in Column A rows 1:200
In column B list the years (E.g. 1950, 1951, ... 2022) this acts as the bins for your histogram
Then in C1, type =countif($a$1:$a$200, b1)
The $ are important so excel doesn't change the range as you drag the formula down*
Double click C1 to copy for the length of your 'years' column.

* technically you could use a$1 not $a$1 since the column ref won't change when you drag down.

Highlight cols B and C and click graph.


 
Posted : 14/06/2022 9:21 am
Posts: 10761
Full Member
 

Isnt a pivot chart / table with a non-distinct count what you need

Yes but the wonderful thing about Excel is that there are about a million different, convoluted, unmaintainable and unnecessary ways of achieving most things that can also be done quite simply. I'm surprised nobody's suggested VBA or PowerQuery yet...


 
Posted : 14/06/2022 9:23 am
Posts: 10315
Full Member
 

Isnt a pivot chart / table with a non-distinct count what you need. Might need to do a bit of prep to get to just the year, should work though.

That


 
Posted : 14/06/2022 9:41 am
Posts: 2324
Full Member
Topic starter
 

Quick and dirty does it - thanks @superficial.

I'm sure that pivot tables and charts etc do the same, but require more Excel mastery than I have.

Thanks all for the suggestions and input


 
Posted : 14/06/2022 11:03 am
Posts: 1318
Free Member
 

My understanding a histogram uses bins to count.

Bin can be 1 in size - so each year in its own bin..


 
Posted : 14/06/2022 11:16 am
Posts: 12507
Free Member
 

sorry, yeah that post wasn't very coherent.

My point was that i took from the OP that they didn't want empty bins. but i think that was more to do with multiple lookups. I wasn't disagreeing with you.


 
Posted : 14/06/2022 12:21 pm
Posts: 3652
Full Member
 

Yes but the wonderful thing about Excel is that there are about a million different, convoluted, unmaintainable and unnecessary ways of achieving most things that can also be done quite simply. I’m surprised nobody’s suggested VBA or PowerQuery yet…

Don't worry, someone will be along to say "Excel is the wrong tool for analysing data, you should learn R/python/COBOL/JavaScript. It's much easier".

Op: use a pivottable/pivotchart.


 
Posted : 14/06/2022 1:04 pm
 Olly
Posts: 5169
Free Member
Posts: 6856
Free Member
 

Don’t worry, someone will be along to say “Excel is the wrong tool for analysing data, you should learn R/python/COBOL/JavaScript. It’s much easier”.

I didn't say that, but since you brought it up: Using Excel to draw graphs is like using the handle of a screwdriver to bash nails in. It'll probably kind of work, but it's way harder than it needs to be and the end result looks shit.


 
Posted : 14/06/2022 1:53 pm
Posts: 2324
Full Member
Topic starter
 

Using Excel to draw graphs is like using the handle of a screwdriver to bash nails in. It’ll probably kind of work, but it’s way harder than it needs to be and the end result looks shit

So what should we be using? PowerBI, Tableau, Python? Any pointers on how/where to build an understanding to use those? Especially for those of us, as mentioned earlier, with limited mastery of more complex Excel formulae etc


 
Posted : 14/06/2022 2:35 pm
Posts: 13594
Free Member
 

So what should we be using?

Excel.


 
Posted : 14/06/2022 4:28 pm
Posts: 10315
Full Member
 

Excel

Just that.  Sometimes it is worth learning a new skill or two to make life a bit easier.  It takes under 40 secs in Excel using a Pivot chart.  Follow the link I put in the second post, 4 mins in.  It's super easy and is useful for way more things as well.   The other suggestions here are all good (well apart from Cobol) but this is pretty much exactly what PivoCharts are for


 
Posted : 14/06/2022 8:34 pm
Posts: 10315
Full Member
 

edit:maybe not


 
Posted : 14/06/2022 8:51 pm

6 DAYS LEFT
We are currently at 95% of our target!