Only sum up unique values in column - excel

| A B
---|-----------------------------------------
1 | Total 1.600
---|-----------------------------------------
2 | Product_A_x1 700
3 | Product_A_x5 700
---|-----------------------------------------
4 | Product_B_x3 300
---|-----------------------------------------
5 | Product_C_x4 200
6 | Product_C_x8 200
---|------------------------------------------
7 | Product_D_x9 400
8 | Product_D_x11 400
9 | Prodcut_D_x8 400
10 |
In Cell B1 I want to sum the unique values from Column B.
B1 = 700 + 300 + 200 + 400
In case a value appears two times it should only be included one time in the sum function.
Is there somehting like a SUMIF formula for unique values?

If you don't have 365, you can use the following:
=SUMPRODUCT(1/COUNTIF(B2:B9,B2:B9&""),B2:B9)
further explained on this page.

In Microsoft365 you can use:
=SUM(UNIQUE(B2:B9))

Related

Sum up unique values in column per criteria in other column (if values are on the left side of the criteria column)

| A B
---|-----------------------------------------
1 | 1.900
---|-----------------------------------------
2 | 700 Product_A
3 | 700 Product_A
---|-----------------------------------------
4 | 300 Product_B
---|-----------------------------------------
5 | 200 Product_C
6 | 200 Product_C
---|------------------------------------------
7 | 700 Product_D
8 | 700 Product_D
9 | 700 Prodcut_D
10 |
With reference to the answer from this question I wanted to sum up the unique values per product in Cell A1.
Therefore, I tried to go with this formula:
A1 =SUM(INDEX(UNIQUE(IF(SUBTOTAL(2;OFFSET(B2:B9;ROW(B2:B9)-ROW(B2);1;1));A2:B9));;1))
However, as a result now I get 0 instead of 1.900.
I assume the issue results because I have the values on the left side of the criteria column.
Do you have any idea how I need to modify the formula to also make it work in the displayed column order?
All you needed to do was to change the 1 into -1 on the OFFSET():
=SUM(INDEX(UNIQUE(IF(SUBTOTAL(2,OFFSET(B2:B9,ROW(B2:B9)-ROW(B2),-1,1)),A2:B9)),,1))

I have data stored in excel where I need to sort that data

In excel, I have data divided into
Year Code Class Count
2001 RAI01 LNS 9
2001 RAI01 APRP 4
2001 RAI01 3
2002 RAI01 BPR 3
2002 RAI01 BRK 3
2003 RAI01 URE 3
2003 CFCOLLTXFT APRP 2
2003 CFCOLLTXFT BPR 2
2004 CFCOLLTXFT GRL 2
2004 CFCOLLTXFT HDS 2
2005 RAI HDS 2
where I need to find the top 3 products for that particular customer for that particular year.
The real trick here is to rank each row based on a group.
Your rank is determined by your Count column (Column D).
Your group is determined by your Year and Code (I think) columns (Column A and B respectively).
You can use this gnarly sumproduct() formula to get a rank (Starting at 1) based on the Count for each Group.
So to get a ranking for each Year and Code from 1 to whatever, in a new column next to this data:
=SUMPRODUCT(($A$2:$A$50=A2)*(B2=$B$2:$B$50)*(D2<$D$2:$D$50))+1
And copy that down. Now you can AutoFilter on this to show all rows that have a rank less than 4. You can sort this on Customer, then Year and you should have a nice list of top 3 within each year/code.
Explanation of sumproduct.
Sumproduct goes row by row and applies the math that is defined for each row. When it is done it sums the results.
As an example, take the following worksheet:
+---+---+---+
| | A | B |
+---+---+---+
| 1 | 1 | 1 |
| 2 | 1 | 4 |
| 3 | 2 | 2 |
| 4 | 4 | 1 |
| 5 | 1 | 2 |
+---+---+---+
`=SUMPRODUCT((A1:A5)*(B1:B5))`
This sumproduct will take A1*B1, A2*B2, A3*B3, A4*B4, A5*B5 and then add those five results up to give you a number. That is 1 + 4 + 4 + 4 + 1 = 15
It will also work on conditional/boolean statements returning, for each row/condition a 1 or a 0 (for True and False, which is a "Boolean" value).
As an example, take the following worksheet that holds the type of publication in a library and a count:
+---+----------+---+
| | A | B |
+---+----------+---+
| 1 | Book | 1 |
| 2 | Magazine | 4 |
| 3 | Book | 2 |
| 4 | Comic | 1 |
| 5 | Pamphlet | 2 |
+---+----------+---+
=SUMPRODUCT((A1:A5="Book")*(B1:B5))
This will test to see if A1 is "Book" and return a 1 or 0 then multiple that result by whatever is B1. Then continue for each row in the range up to row 5. The result will 1+0+2+0+0 = 3. There are 3 books in the library (it's not a very big library).
For this answer's sumproduct:
So ($A$2:$A$50=A2) says to return a 1 if A2=A2 or a 0 if A2<>A2. It does that for A2 through A50 comparing it to A2, returning a 1 or a 0.
(B2=$B$2:$B$50) will test each cell B2 through B50 to see if it is equal to B2 and return a 1 or 0 for each test.
The same is true for (D2<$D$2:$D$50) but it's testing to see if the count is less than the current cells count.
So... essentially this is saying "For all the rows 1 through 50, test to find all the other rows that have the same value in Column A and B AND have a count less than this rows count. Count all of those rows up that meet that criteria, and add 1 to it. This is the rank of this row within its group."
Copying this formula has it redetermine that rank for each row allowing you to rank and filter.

Add non-existent numbers with a zero value in Excel

I have lot of sequential data in Excel.
The missing number in the sequence for Column A, should be populated with zero value in column B.
What formula i could use for this?
Data in excel sheet as below:
A | B
0 | 4
1 | 6
4 | 4
6 | 7
Expected output:
A | B
0 | 4
1 | 6
2 | 0
3 | 0
4 | 4
5 | 0
6 | 7
In B1 of your second table
=IFERROR(VLOOKUP(A1,original_table,2,0),0)
and drag down. Replace original_table with a reference to your first table

How to multiply the reverse of a column with another column in excel?

Suppose i need to multiply the entries in these two columns in the following order in MS Excel
This is just an example
A | B
1 | 5
2 | 10
3 | 15
4 | 20
bolck1:1*5
block2:(2*5)+(1*10)
block3:(3*5)+(2*10)+(1*15)
block4:(4*5)+(3*10)+(2*15)+(1*20)
how would i do it?
I used SUMPRODUCT(A4:A1,B4:B1) but it returned the same old sum 150 as was the case with SUMPRODUCT(A4:A4,B1:B4).
You could add a helper column. In C1 put:
=SUMPRODUCT(A1*INDEX($B$1:$B$4,1):INDEX($B$1:$B$4,COUNT($B$1:$B$4)-(ROW(1:1)-1)))
Drag it down then total the results:

Excel, Libreoffice/Openoffice Calc: count 'right' answers

I have a table with students' answers to 20 math problems like this:
A | B | C | D | E |...
------------+-----+-----+-----+-----+...
problem no | 1 | 2 | 3 | 4 |...
------------+-----+-----+-----+-----+...
right answer| 3 | 2 | A | 15 |...
------------+-----+-----+-----+-----+...
student1 | 3 | 4 | A | 12 |...
student2 | 2 | 2 | C | 15 |...
student3 | 3 | 2 | A | 13 |...
Now a need a column that counts the 'right' answers for each student.
I can do it this so: =(IF(D$3=D5;1;0))+(IF(E$3=E5;1;0))+(IF(F$3=F5;1;0))+...
...but it's not the nicest way :)
This is a typical use case for SUMPRODUCT:
A B C D E F G
1 problem no 1 2 3 4
2 right answer 3 2 A 15 right answers per student
3 student1 3 4 A 12 2
4 student2 2 2 C 15 2
5 student3 3 2 A 13 3
Formula in G3:
=SUMPRODUCT($B$2:$E$2=$B3:$E3)
If there are more problem numbers, then the column letters in $E$2 and $E3 have to be increased.
How it works:
SUMPRODUCT takes its inner functions as array formulas. So the $B$2:$E$2=$B3:$E3 becomes a matrix of {TRUE, FALSE, TRUE, FALSE} depending of if $B$2=$B3, $C$2=$C3, $D$2=$D3, $E$2=$E3.
In Libreoffice or Openoffice TRUE is 1 and FALSE is 0. So the SUMPRODUCT sums all TRUEs.
In Excel you have to get the boolean values in numeric context first. So the Formula in Excel will be =SUMPRODUCT(($B$2:$E$2=$B3:$E3)*1).
The formula in Row 3 then can be filled down for all student rows. The $ before the row number 2 ensures that thereby the row of the right answers not changes.
Greetings
Axel

Resources