Calculate a value for 2 different set of IDs in excel - excel

My excel table has 5 Rows: Id, ColA, ColB, Count and Test.
ID A B Count Test
2 a low 5 -
2 b high 6 -
2 c low 7 -
2 d high 8 -
2 e low 9 -
1 a low 1 =(1-5)
1 l high 2 -
1 e low 3 =(3-9)
I want to Calculate the value of Test for only rows with Id = 1
If Value of ColA for ID 1 = Value of of ColA for ID 2 and
Value of ColB for ID 1 = Value of of ColB for ID 2
then calculate the difference between the Count Values
else
0
The Excel Table is connected to Sql Query. Every time I refresh it the table has a different number of rows.
I tried using VLOOKUP in TEST column where Id = 1 and specified the array table as the first 5 rows (only with Id = 2) but it doesn't seem to work because when I refresh the table the second time there are only 2 rows for Id = 2.
I want the TEST column value to be automatically calculated each time the table is refreshed. Thanks!

use countifs to find if it exists, and sumifs to return the value:
=IF(AND(A2=1,COUNTIFS(B:B,B2,C:C,C2,A:A,2)),D2-SUMIFS(D:D,B:B,B2,C:C,C2,A:A,2),0)

Related

Excel - assign values based on the first unique item

I have got an excel question that I can not answer. Here is my table:
ID Key Count Unique Available Text Results
1 0 Text-1 Dupe-Y
2 1 Y Text-1 Y
3 0 Text-1 Dupe-Y
4 0 Text-1 Dupe-Y
5 1 N Text-2 N
6 1 Y Text-3 Y
7 0 Text-2 Dupe-N
8 0 Duplicate Text-2 Dupe-N
9 0 Duplicate Text-2 Dupe-N
10 0 Y Text-2 Dupe-N
Id Key is just unique key.
Count unique picks up the first time each value in column Text appears. Available can have Y, N, Duplicate and Text is the main column I need to analyze my table. The Results are for the first time each value in Text appears (Count unique = 1), if there is a value in Available then that is the value I need, if Count Unique is 0 then is either Dupe-Y or Dupe-N depending on the value in Available.
I tried with a formula like this one but got stuck after initial progress. =IF(B2=0,"",IFERROR(IF(COUNTIF(D:D,D2)>1,IF(COUNTIF($D:$D,D2)=1,"",C2),1),1))
Note that the column Results is the one I need to populate with a formula that is not affected by sorting or lack of it.
I guess you got all those values and you just need a formula for column Results.
My formul will work only if the data is sorted like in your example. If sorting changes, formula will fail:
My formula is:
=IF(B2=1;D2;"Dupe-"&RIGHT(G1;1))

Sum values of one column depending on the ID of another

I have a table with many values as such (this is an oversimplified example):
IDx
Namex
Pricex
1
a
5
2
b
2
1
a2
5
3
c
3
2
b2
9
and another table with only the ID, in which I'd like to add a column that shows the addition of all the values that match that ID, in this example:
IDy
Totaly
1
10
2
11
3
3
I'm guessing this is a combination of vlookup with sum or sumif, I've tried so far:
=SUM(VLOOKUP(IDy1,$IDx$1:$IDx$5,$Pricex$1:$Pricex$5),// don't know how to proceed here
Try this:
B5:B9 = IDx
B16,D5 = Price
=SUMIF(B$5:B$9,B16,D$5:D$9)

Convert sql to excel formula

I have 2 tables in excel.
Table 1
Item Quantity_Required Quantity_Remaining
A 5
B 10
C 3
Table 2
Source Item Quantity
1 A 2
2 A 1
1 B 5
My result should be to fill in Quantity_Remaining column in Table 1
Table 1
Item Quantity_Required Quantity_Remaining
A 5 2
B 10 5
C 3 3
The logic in SQL code is as follows.
SELECT A.Item,
A.Quantity_Required,
A.Quantity_Required - B.Quantity as Quantity_Remaining
FROM Table1 A
LEFT JOIN
(SELECT Item,
SUM(Quantity)
FROM Table2
GROUP BY Item) B
ON A.Item = B.Item
I need pointers on how to translate this to Excel.
For data placed in excel sheet like below, you can use this formula:
=$B2-SUMPRODUCT(($A2=$B$8:$B$10)*($C$8:$C$10))
So the second part of formula SUMPRODUCT is looking for cells in range B8:B10 which match with A2 and then taking their values from column C and adding them.

Excel distinct count in Pivot Table by all period segmented by month

Okay, as I see it now this isn't the real problem.
I need to get distinct count of customers by month, taking into account all
previous months. What I get by distinct count now is the unique count for a single month, but not taking into account the whole period. That is done by grand total but i need it segmented by month. Is there any way to fix this?
What I have now:
-2016.04 Subtotal 3
A 1
B 1
C 1
-2016.05 Subtotal 3
A 1
B 1
G 1
-Grand Total 4
What I need:
-2016.04 Subtotal 3
A 1
B 1
C 1
-2016.05 Subtotal 1
A 1
B 1
G 1
-Grand Total 4

In Excel how do subtract values from list table when I preform a transaction?

If I have two tables where I have list of things in 1 table and the other table serves as a transaction table. But every time I do a transaction the value of units in the transaction should be subtracted from the lists table. Can anyone please help?
Let's say table 1 looks like this:
A B C
1 Item Start Value Current Value
2 ---- ----------- -------------
3 1 20
4 2 100
5 3 95
and table 2 has transactions recorded as a list of Item numbers in column E and associated value movements in column F, then the formula in C3 should be:
=B3-SUMIF(E:E,A3,F:F)
This formula can then be copied down for the other entries in table 1

Resources