Calculated column to show number of items selected in a multichoice field - sharepoint

In SharePoint I have a table with a lookup column that takes in multiple values. I am having a problem finding a code for a calculated column that counts how many values the user chose. For example,
Favorite Ice Cream
1 Vanilla; Chocolate; Strawberry
2 Cookies and Cream; Mint
3 Coconut; Chocolate; Butter Pecan; Strawberry
And an adjacent column will be...
Number of total Ice Cream
1 3
2 2
3 4
Thank you in advance!

Related

Indexing multiple columns in Excel, return neighboring column

I am working on an excel sheet that will help me with meal-planning. Currently, I have my data stored in a manner like demonstrated below:
**Monday**
Breakfast Bagel 1 Cream Cheese 1
Lunch Spinach 1 Eggs 4 Cream Cheese 1
Dinner Pork 1 Eggs 2
**Tuesday**
Breakfast Cereal 2 Milk 1 Eggs 3
Lunch Bagel 1 Butter 1
Dinner Eggs 2
CURRENT OUTPUT:
Ingredients Needed:
Eggs 2
Bagel 2
Spinach 1
Pork 1
Cereal 2
Milk 0
Butter 0
Cream Cheese 0
Where the numbers represent the number of servings of each ingredient I need to buy.
The problem I am facing is that my current formula:
=INDEX($C$12:$C$58, SMALL(IF(ISNUMBER(SEARCH($B$60, $B$12:$B$58)), MATCH(ROW($B$12:$B$58), ROW($B$12:$B$58))), ROW(B1)))
Only indexes one row at a time. For example, if I am searching for how many Eggs I need to buy for the week, the formula would return 2 eggs (because it is only searching column B for Eggs and returning column C).
Is there a work-around that would allow me to be able to return the full number of ingredients I need to buy? I realize I could index each column individually, however, since I have many ingredients (100+), using my current formula doesn't seem feasible.
Any help is massively appreciated
You can use SUMIF, where the sum range is offset from the criteria range. For example, for simplicity, let's say that C12 to H19 contains the data (ingredient and quantity), try...
=SUMIF($C$12:$G$19,B60,$D$12:$H$19)
...where B60 contains the ingredient of interest. Notice that the sum range D12:H19 is offset from the criteria range C12:G19.

Grand Total Issue in Cross Table of Spotfire

When I use FIRST(CG1) in 'Cell Values' the grand total is not summing up instead its showing one of the values from the result of FIRST(CG1).
Please advise if we have to always use sum(XXX) to get the grand total summed up.
Short answer, yes if you want the Grand Total to be a summation of your data. Applying a grand total to a different aggregation will have different results.
AVG will average the averages of your Category Axis
MAX will take the MAX of the Max for each category
Cumulative Sum will take the "Last" value in your Category since it doesn't have any additional values to SUM up.
Product will take the Product of Products
First and Last you are already aware of.
Long Answer:
You actually CAN sum the first value of a column from a column grouping.
For example, consider the following data set.
[Grouping] [Food] [Color] [Weight]
Fruit Apple Yellow 4
Fruit Apple Green 2
Fruit Apple Red 4
Fruit Banana Yellow 5
Fruit Banana Brown 2
Fruit Orange Orange 3
Vegetable Carrot Orange 4
If, in your custom expression, you put
Sum(if(RankReal([Grouping], "ties.method=first", [Food]) = 1, [Weight], 0))
it will find the first instance of each food in your data set, so regardless of how you group the left, your results, subtotals, and grand totals will sum only the first instance of each food.
So you will be able to see the following:
Fruit Apple 4
Banana 5
Orange 3
Subtotal: 12
Vegetable Carrot 4
Subtotal: 4
Grand Total: 16

How to sum a reference column with a custom ordering

I'm trying to sum a column that is from an input table to link to a reference table that a user can select inputs to create a "group." I think an example is better here:
Inputs
Key Type Name Count lookup_value
1 Fruit Apple 3 1 - Apple
2 Fruit Orange 5 2 - Orange
3 Fruit Pear 6 3 - Pear
4 Veggie Broccoli 3 4 - Broccoli
5 Veggie Celery 2 5 - Celery
The user puts these inputs in, and from another screen is able to customize a group (each of the selection is from a dropdown,lets call each array of data input_column name such as input_lookup_value for our formulas). Using the following formula in a cell next to "Total Pieces of Food,"
=sumproduct(--(A1:A3=input_lookup_value),input_count)
We will get the correct answer of 14, as below.
Group Name: Food Sally Likes
Total Pieces of Food 14
Item
A1 1 - Apple
A2 2 - Orange
A3 3 - Pear
However, if the user is to put in just Celery in cell A1, the formula will not work, and the "Total Pieces of Food" will return 0, since the order does not match the Input table order. Is there another formula or way I can attack this that will return the correct count, and still allow the user to enter the list in any order?
To put what #Jeeped (with his permission) suggested in the comments into an official answer:
The formula is:
=SUM(SUMIFS(Sheet16!D2:D6, Sheet16!E2:E6, A4:A6))
This is an Array Formula, So confirm with Ctrl-Shift-Enter

comparing two columns in excel (VLOOKUP not working)

I have been breaking my head with this problem since morning and I haven't found a solution. Please give your valuable pointers if possible, so that I can try to find the solution.
I basically have two sets of data- an old list and a new list. I wish to compare the new list( comparing name and country together) with an old list, since the new list has a few additional entries. Later on, I would like to create a new list with common entries from both old and new list and add all the new entries below the common ones ( if possible, else I will do that manually later on but I would like Excel to tell me that this is a new entry). Sorry, if this has not been well explained, but maybe the following illustration helps
Old List
Item No. Name Country
1 Apples Italy
3 Banana Spain
4 Grapes Slovakia
5 Pineapple Greece
8 Banana Czech Republic
14 Apples India
23 Pineapple Hungary
19 Peach USA
2 Strawberries France
New List
Item No. Name Country
4 Grapes Slovakia
Mango Pakistan
14 Apples India
Oranges Mexico
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Avocado Netherlands
Expected Output:
List with common serial No.s based on common names from both lists
Item No.Name Country
4 Grapes Slovakia
14 Apples India
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Mango Pakistan
Oranges Mexico
Avocado Netherlands
As can be seen in this attachment, I have an old list with Item No., Name and Country. Let's assume that the item numbers have been classified based on some code words. In the second list, there are again Item No.s, Name and Country but some item numbers haven't been filled ( since they are new and have not yet been sorted). Now, I want Excel to compare the names AND countries of both data and provide the common Item No. output if there is a match. If there is no match, then I would like Excel to tell me that this is a new entry. I looked up on various forums and I realized that VLOOKUP command only allows me to search on Name OR Country would give me the common entries of Names/Countries respectively but not Item No.s. Is there any formula that could help me solve this problem?
Just paste the list together, then sort it, and then remove the duplicates. Removing duplicates is built-in into Excel starting from version 2007, you will find it in the Data ribbon (see http://office.microsoft.com/en-001/excel-help/filter-for-unique-values-or-remove-duplicate-values-HP010073943.aspx).
To use VLOOKUP just concatenate Name and Country, for example, B2 & "-" & C2. You can then do a lookup on the concatenated values in your source table:
VLOOKUP(B2 & "-" & C2,NewList!D2:E100,2,False)
This assumes that the concatenated column is in D in your new table, and that you've copied the numbers to column E (VLOOKUP can't look to the right). I put in the dash for readablility and to avoid the chance that a Country ends with a number, unlikely as that might be.

Count and average data inside categories under two types of conditions

I'm working on Excel with a lot of data and I'm having difficulty with knowing how to sort through it to get some important numbers. I have minimal Excel experience.
Right now I'm struggling with knowing how to get the average in the difference between two columns. The trick is that I have to get the average in difference when column A is less that column B and then, the same when it's more. And all that within a category.
So for example let's say I have 3 categories: Football, Soccer, and Basketball (these are just made up ones).
So in column A, I have: Soccer, Football, Basketball. Then, in column B and C, I have the scores for John and Adam for the last 3 months, respectively. Lastly, in column D, I have the differences between their scores.
So, for example:
Category John Adam Differences
Soccer 5 3 2
Soccer 6 2 4
Soccer 3 5 2
Soccer 4 0 4
I want to create a table for within each category I have a table like below:
NÂș of cases Avg. Difference between John and Adam
When John's score is >
When John's score is <
When they are equal
Is there some type of formula where I can say something like this:
If the category is Soccer (the category being in column A), take the difference between John's score (column B) and Adam's score (column C) when John's score is larger than Adam's score, then calculate the average of those differences? Then, I would use the same formula but tweak it when John's score is smaller.
Additionally, would there be a formula where I can also, calculate within the category Soccer, how many times John's score is bigger than Adam's?
My data is much larger and I can't do this manually.
A B C D
1 Sport John Adam Differences
2 Soccer 5 3 2
3 Soccer 6 2 4
4 Soccer 3 5 -2
5 Soccer 4 0 4
6 Basketball 20 15 5
7 Basketball 7 13 -6
8 Basketball 26 10 16
9 Basketball 8 11 -3
Type in D1:
=B1-C1
Drag the formula in Column D to all rows which there are values in columns A, B and C.
Create the PivotTable.
Drag Sport to "Row Label" field. Drag Differences to "Row Label" field under Sport.
Drag Differences to "Values" field as: Count of Differences (same way the previous question)
Drag Differences to "Values" field (below Count of Differences), and set the mathematical operation as "Average" of Differences (left-mouse click Differences, choose "Values fields settings" and select "Average").
Give a right-click mouse in cell A5 (see picture bellow) and select "Group" option.
Set "Starting at" = 0; "Ending at" = 1000; "By" = 1000 (as in the picture below). Click ok.
You will have in each Sport, the count (frequency) and average Differences values for two groups:
When the Difference B1-C1 is negative; and
When the Difference B1-C1 is zero or positive.
The average of Differences when the score is equal will be always zero.

Resources