views:

3264

answers:

8

Is there a way to create a SharePoint calculated column that returns a count of the number of entries in a list? So If I have 3 customers in my list with the company "Starbucks" I'd like the field to return "3"

+1  A: 

No, I don't think there's a way to do this using the out-of-the-box calculated column.

Some other ways you could accomplish this are:

  • Create a view for your list that with a group by on the company field and include the total count. This is easiest, but might not be exactly what you're looking for.
  • Create a custom column type that executes a CAML query to find items that you're interested in. There is a learning curve if you've not done it before and if the list that you're adding this custom column to has lots of rows, you'll be executing a query for each row which is inefficient - it'll be OK for a small number of rows.
  • Use an event handler on the list that updates a column value each time a new item is added or removed from a list. This is easier, but can also be inefficient if you have a large number of items in your list.
dariom
Actually what I'm trying to do is filter a list so that the only items listed are where there is 2 or more items from that company. I assume I need to create a calculated column to do this. So my calculate column counts how many times each company is in my list...and then I can filter by saying When (my calculated column > 1). Is there another way to do this?
Whozumommy
Sam Yate's answer is the easiest way to do this. Accept his answer!
dariom
+1  A: 

As dariom said (damn my slow typing skills, +1!), only the current row can be operated on with calculated columns by default in SharePoint. There are a couple of documented workarounds involving SharePoint Designer or jQuery, though.

vinny
+7  A: 

(Edited some wording for clarity per suggestion from dariom).

You may be able to get what you want with another list using a not-so-well-known variation of a lookup column.

Let's say you have a list called Companies with values in the title column like "Starbucks", "Peets", etc. Now you also have the Customers list you refer to, but the "Company" column is a lookup column pointing to the title column in the Companies list.

You can add a count very similar to what you described to your Companies list. Go to your Companies list, add a column of type "Lookup" referring to the Customers list and you'll notice that in the drop-down area where you define the lookup if you point back to the Customers list, you'll have a new option called "Count Related". This is here automatically because it recognizes that the Customers list has a lookup pointing back to this one. Select that Count Related option and now your Companies list will have a column counting how many customers are associated with that company.

No coding, Javascript hacks, or anything. Just hidden SharePoint auto-magic.

Sam Yates
Sam, this is perfect (+1) - I didn't know this was possible! I was a bit confused at first when I read your instructions. Suggest editing 'Go add a column of type "Lookup" and you'll notice...' to 'Go to your Companies list, add a column of type "Lookup" referring to the Customers list and you'll notice...' to be more explicit.
dariom
Neat! +1! (>15 character comment limit? Really?)
vinny
A: 

I'm trying to accomplish the same thing but I cannot find the "Count Related" option as described by Sam. I have a SharePoint list called "Tasks" that includes a Lookup column called "Status" that links to another SharePoint list. I want to count the number of tasks with each different status. Thanks!

Lauren
If you have a follow up question you should post it asa new question, not as an answer to an old question.More people will read it since old questions are not frequented very much.You of course can always link back to this page for reference if you want to.
sth
A: 

Awsome Awsome solution. Thank You Sam. Lauren. when you create a lookup list make sure you click on the drop down and you will see the column something like this Companies(Count Related). I think this has to be lookup column from same list. I hope this helps

A: 

You can get a Count of specific list items in an XSLT Data View

To do this you will need SharePoint Designer.

Right click on your SharePoint List view (ensure the list view contains the field you want to filter by) select convert to XSLT Data View. Then in the Data Source Windows select Data Source Tab and drag and drop the field you want to get a total on for the specific items into where you want it displayed in your XSLT Data View. Click on the numerical value that is showing you should get a lightening bolt icon, select the drop down and choose Count, then select again and choose Filter. Select "Click here to add a new clause" then choose your field name again and enter your unique value as Starbucks and click OK, you can repeat this process for other fields you want the totals on. You will now see the total number of Starbucks items in the list.

Niall Gowanlock
A: 

I got something similar to work in a way similar to Niall. Basically, I:

  1. Based on the source list, created a Data View Web Part (DVWP) on a "test" web part page.
  2. Added the footer column, which gives a count.
  3. Set the filter for my conditions (i.e., the items I want to count).
  4. In the code, deleted the recurring items row.

I was left with just the footer, which displayed a filtered count for all the list items. I further customized the footer by taking out the shaded background. Finally, I exported this web part and imported it onto the page where I wanted users to see a total of items in the list (which met the criteria).

A: 

Hi all ,

Is there are way to assign active directory information in calculated column, if it is then please let me know ASAP

ashu