Excel - Sum of values based on a drop down defining whether they are negative or positive - excel

I've tried searching for posts specifically on this, but am struggling to find what I'm looking for. I'm trying to do some fairly basic calculations based on a value in a drop down field for each row which determines whether the value is negative or positive.
In the example below, I would like to sum all the values in Column B based on a drop down value (Column C) which defines whether the value in column be should be added or subtracted from the total amount in C10.
I'll be honest, I have no idea how to even begin working out how to write the formula for the Credit/Debit values based on the drop down.
A B C D
1 DATE VALUE TYPE DESCRIPTION
---- ----- ---- -----------
2 02/03/2015 £150 Debit Currency Exchange
3 20/04/2015 £200 Debit Currency Exchange
4 04/05/2015 £1000 Credit Currency Exchange
5
6
7
8
9
10 TOTAL ADJUSTMENTS: £650
I'm guessing I need to somehow use the SUMIF statement to define whether the type in Column C is Debit or Credit and then add/substract the corresponding value some how from the total amount?
Many thanks in advance for any assistance you may be able to offer.

Try
=SUMIF(C2:C9,"Credit",B2:B9)-SUMIF(C2:C9,"Debit",B2:B9)
The first Sumif sums up all the credits, the second Sumif sums up all the debits and the debit sum is then subtracted from the credit sum.

Related

Only show the sum of a column if there are at least 3 records in another column

I have 3 Columns of data. Column E = Duration. The user will enter a number of days (Duration) for 20 employees. Column F = Pay. List of wage for each employee. Column R = Pay Total. This is a calculated field based on the number of days (Duration) and the employees pay (Pay).
To keep my employees from finding out their coworkers pay I only want to see a sum for Column C if there are at least 3 records in Column A.
I found this Sum only if 3
From that answer I tried to use =IF(COUNTIF(E2:E15,">2"),SUM(R2:R15))
What this does is only returns records with a duration of greater than 2 days. I don't care about the number of days. I want the indicator to be that there are 3 cells populated in this column.
I think the only issue with the formula is the CountIF part. I need to know what I should use to count cells not days.
Screenshot of My Sheet
In the image above you can see that it's returning a sum bc both records are greater than 2. Like I said before I don't care what number is in the cell I just want to see the sum if there are more than 2 cells populated in that column.
Thanks for any help
As per my understanding of the question, I came up with this solution. Give it a try.
=IF(COUNT($E$2:$E$15)>2,SUM($R$2:$R$15), 0)
This formula would give what you want
=IF(COUNTA(E2:E15)>2,SUM(R2:R15),"")
This would show sum only if count of non empty cells is greater than 2 in Range "E2:E15" else it would show empty.

Looking for a formula using the table below to bring in the correct credit value based on what the discount value and the product is

Looking for a formula using the table below to bring in the correct credit value based on what the discount value and the product is. For example I know for books with discountt value of .57 the credit (based on the table) should be 66.67% but how can I achieve it through formula? Any help would be greatly appreciate. Thank you!
After using the formula from #Scotts Answer:
Use INDEX with two MATCHES in the second criterion:
=INDEX(D:D,MATCH("Supplies",A:A,0)+MATCH(.57,$B$2:$B$8)-1)
This first finds the first instance of Supplies in Column A and returns that row number. Then it adds where it finds .57 in the first Min break down relatively then subtracts one.
So for this it finds Supplies in row 9 then it finds where .57 hits in the 3 cell in $B$2:$B$8. So the math is 9+3-1 which is 11 which would return row 11 in column D.

Excel database - formula multiplication exchange rate by date

I am creating some accounting papers and I need multiplicate USD exchange rate with our currency by date. I tried everything, but I don't know how to do it..
Here is example:
DATE | USD | CZK
1.1.2018 | 2$ | USD Price * CZK Price by same date
2.2.2018 | 2$ | USD Price * CZK Price by same date
EXCHANGE RATE
1.1.2018 | 22
2.2.2018 | 23
(It means that price on 1.1 will be 44CZK and 2.2 will be 46CZK)
And this I need do for every day in year.
So hand writing isn't possible. I need some formula for it.
Can you help me please? I know that it can be by vlookup and If..
Thanks!
You can use INDEX with MATCH to achieve this as well and wrap in IFERROR in case a match for the "date" string is not found in the lookup column. If a match is found in the lookup column E, for the "date" string in column A the number returned for the match is passed as a row number argument for Index on column F which returns to rate in the same row as the match was found. This is then multiplied by column B.
You would alter the ranges $F$2:$F$3 and $E$2:$E$3 to encompass all your actual rows in those columns.
In B2 and drag down
=IFERROR(B2*INDEX($F$2:$F$3,MATCH(A2,$E$2:$E$3,0)),"")
Yes, you can muliply with the exchange rate in your cell while doing the lookup at the same time, so in Cell C2:
=B2*(VLOOKUP(A2,$E$2:$F$3,2,FALSE))
I.e. VLOOKUP(A2,$E$2:$F$3,2,FALSE) will give you the exchange rate,
A2: Lookup value, the date in our case.
$E$2:$F$3: Where we can find the date in your "search area". Notice that the date we search for, needs to be in the first column of our "search area".
2: In our "search area", from which column number should we return our return number/value. In our case our "search area" is two column, where we want the result to be return from the 2nd column of column E and F.
FALSE: Search for exact match.
When the exchange rate is found we mulptiply it with the dollar amount, i.e. B2 * Vlookup() :)

Find distinct values based upon multiple columns

I have a spreadsheet of sales with (to keep the example simple) 3 columns
NAME -- STATE -- COUNTRY
It's easy to find how many sales. (sum all the lines)
I can find out how many customers I have but how about finding out how many customers from a particular state (and country)
NAME -- STATE -- COUNTRY
p1----- CA------ USA
p2----- CA------ USA
p1----- CA------ USA
p1----- CA------ USA
p3----- NY------ USA
p3----- NY------ USA
The above example would give 2 unique customers from CA and 1 unique customer from NY and 3 from the USA
EDIT:
The desired result from the above table would be
STATE - UNIQUE CUSTOMERS
CA ---- 2
NY ---- 1
COUNTRY - UNIQUE CUSTOMERS
USA ---- 3
Assuming your data have headers in row 1 of columns A, B, and C, follow these directions.
In cell F1 enter STATE.
In cell G1 enter COUNT.
In cell F2 enter this array-formula (must be confirmed with Ctrl+Shift+Enter↵):
=IFERROR(INDEX(B$2:INDEX(B:B,COUNTA(B:B)),MATCH(0,COUNTIF(F$1:F1,B$2:INDEX(B:B,COUNTA(B:B))),)),"")
In cell G2 enter this regular formula (confirmed with Enter):
=IF(LEN(F2),COUNTIF(B2:B13,F2),"")
Select F2:G2 and copy.
Now select F3:F51 and paste.
UPDATE
The nature of the question changed. The first formula is exactly the same as before. It gets the distinct states in the source data and culls them so they display with no blanks.
The second formula is now different. It needs to count the number of distinct customers in each state, and it is now an array formula confirmed with Ctrl+Shift+Enter↵).
=IF(LEN(F2),SUM(IF(F2=$B$2:$B$50,1/(COUNTIFS($B$2:$B$50,F2,$A$2:$A$50,$A$2:$A$50)),)),"")
This formula (entered as an array formula CTRL-SHIFT-ENTER) will count the number of occurrences of a Name in MyState
=COUNTIFS(Names,Names,States,MyState)
So if MyState="CA" this would return {3;1;3;3;0;0}
To get the number of names in CA you can sum the reciprocals of this array, EXCEPT taking the reciprocal of zero is invalid/infinite. So wrap the formula above in a test for zero: if it's zero, output zero, otherwise take the reciprocal (one of the rare situations where you get to set infinity equal to zero!):
=IF(COUNTIFS(Names,Names,States,MyState)=0,0,1/COUNTIFS(Names,Names,States,MyState))
(Still an array formula.)
For CA this will return {0.333333;1;0.333333;0.333333;0;0}
The final step is to sum with the array formula:
=SUM(IF(COUNTIFS(Names,Names,States,MyState)=0,0,1/COUNTIFS(Names,Names,States,MyState)))
It's possible that this could return say 2.99999... instead of 3 due to rounding errors. If that's a problem you can fix it by wrapping it with the ROUND function or setting the display format zero decimal places.
It should be straightforward to modify this to count by country. Hope that helps.
Since the question also has an 'google-spreadsheets' tag, this would be my suggested formula to use in a google spreadsheet:
For the state counts:
=query(unique(ArrayFormula({A2:A&B2:B, A2:C})), "select Col3, count(Col1) where Col3 <> '' group by Col3 label count(Col1)''",0)
And for the country counts:
=query(unique(ArrayFormula({A2:A&B2:B&C2:C, C2:C})), "select Col2, count(Col1) where Col2 <> '' group by Col2 label count(Col1)''",0)
Also see this example spreadsheet.
Easy with a PivotTable in Excel 2013:
Also easy with Google Spreadsheets:

How can I remove non-matching values in two different columns and sort in Excel?

I have several columns of data in my Excel spreadsheet.
Originally, I had two different spreadsheets, as they were generated from reports in a software application.
One of the spreadsheets contains the names of individuals who have had transactions with us in the past year. The other spreadsheet contains the names and the phone numbers. I copied and pasted the columns with the names and phone numbers into my spreadsheet with just the names of people who have purchased something from us in the past year.
My ultimate goal is to extract the names and phone numbers of only the names that have purchased something in the past year.
My column for the past year contains 1,002 names, while my master customer list (with phone numbers) contains over 20,000 individuals. I need the phone numbers of all of the individuals that have purchased something from us in the past year, but I don't want to have to manually go through 1,000 names (and, essentially, 20,000+ to find the match).
If I can achieve my goal without having to use VBA, that would be great. If this is the only route I can take, then I will go that route, but I would like to avoid coding if possible. (This is simply due to time constraints.)
The VLOOKUP function is likely the best solution for you. From the Excel documentation, it:
Looks for a value in the leftmost column of a table, and then returns
a value in the same row from a column you specify. By default, the
table must be sorted in an ascending order.
Note well the implication of that last sentence: the column you're searching in (leftmost column of the lookup table) must be sorted in ascending order for this function to produce the correct results.
Taking a simple example, let's say you have Sheet1 in your Excel workbook with the following information:
A B C
1 Name Transactions Phone
2 Sally 3
3 Alice 5
4 Joe 2
5 Jon 1
You need to add their phone numbers to this sheet, from another workbook. Let's say your phone number information in the other workbook looks like this:
A B
1 Name Phone
2 Alice 2222222
3 Bill 3333333
4 Bob 4444444
5 Jim 5555555
6 Joe 6666666
7 Sally 7777777
8 Sue 8888888
9 Tom 9999999
Take the following steps to add the phone numbers to Sheet1 in the first workbook:
Copy the phone information into a blank sheet in the first workbook. Let's call this Sheet2 for this example.
Make sure the phone information is sorted ascending by the Name column (A), because that's the leftmost column and thus the lookup column.
In cell C2 of Sheet1 (the empty phone cell for Sally), enter: =VLOOKUP(A2, Sheet2!A$2:B$9, 2,FALSE).
Drag-copy this formula down to the remaining cells in the Phone column.
Result:
A B C
1 Name Transactions Phone
2 Sally 3 7777777
3 Alice 5 2222222
4 Joe 2 6666666
5 Jon 1 #N/A
Notes:
The second parameter (Table_array - the lookup data range) should not include the column headings. As you can see, it's Sheet2!A$2:B$9 so it includes the information from rows 2 to 9 in columns A and B.
The last parameter (Range_lookup) should be set to FALSE so you don't pick up the information from the closest match. Note how Jon has no matching phone number record, so his Phone is set to "#N/A" - otherwise he would have been assigned Joe's phone number since that's closest match to Jon.
Parameter documentation:
Lookup_value is the value to be found in the first column of the table, and can be a value, a reference, or a text string.
Table_array is a table of text, numbers, or logical values, in which data is retrieved. Table_array can be a reference to a range or
a range name.
Col_index_num is the column number in Table_array from which the matching value should be returned. The first column of values in
the table is column 1.
Range_lookup is a logical value: to find the closest match in the first column (sorted in ascending order) = TRUE or omitted; find
an exact match = FALSE.

Resources