Getting a modified range of cells - excel

I need to apply a function to a range of cells and then getting the modified version of this range.
I need to apply LEFT(A1;FIND(" ";A1&" ")-1) to a range (A1:A6) and get the range back so that =SUMIFS(B1:B6;A1:A6;"AAA") works.
Actual problem:
A company sells drugs and they want to know the total sales of a specific drug sold.
A | B
1 AAA tbl 20x50g | 3
2 AAA tbl 90x50g | 4
3 BBB 10% raz 1ml | 1
4 BBB 2% raz 1 ml | 8
5 BBB tbl 12x2,5 | 1
6 CCC vet 48x1kg | 7
On the next list is a list with only the "generic" name:
C | D
1 AAA | ?
2 BBB | ?
3 CCC | ?
I need to get the values in D1.
So far I have came to:
=SUMIFS(B1:B6;A1:A6;LEFT(A1;FIND(" ";A1&" ")-1))
This will compare everything in A1:A6 with the first company (AAA). If it gets a match (A1, A2) it will take the value from the B1:B6 and the answer would be 7.
But I need to apply the "get first word" function
LEFT(A1;FIND(" ";A1&" ")-1)
to the range A1:A6
EDIT:
My bad. It appears I was trying to reinvent fire by spiting water on wood.
The problem was elsewhere.
The values in B were being produces through
=IF(AB34=0;" ";AB34*$Y34)
and the TRUE clause (" ") messed up the math.

You would use the SUMPRODUCT with LEFT(FIND()):
=SUMPRODUCT((LEFT($A$1:$A$6;FIND(" ";$A$1:$A$6 & " ")-1)=D1)*$B$1:$B$6)

Related

Excel qty IN/qty OUT formula

I need help with a formula calculating qty in and out based on need date where oldest date pulls first if the PN matches an item on the inventory list.
I have a master list of total on-hand inventory.
PN
Total QTY on-Hand
aaa
10
bbb
15
ccc
0
I need to compare the total on-hand inventory list with individual order lines, but I cannot figure out how to get the remaining balance to be the starting balance (QTY OH column) of the next line. Below is what I would like it to look like.
Date Due
PN
QTY OH
QTY Demand
QTY Balance
1/15/2023
aaa
10
2
8
1/17/2023
aaa
8
3
5
1/20/2023
aaa
5
4
1
1/19/2023
bbb
15
11
4
1/25/2023
bbb
4
6
-2
1/30/2023
bbb
-2
3
-5
1/11/2023
ccc
0
8
-8
1/16/2023
ccc
-8
7
-15
1/21/2023
ccc
-15
4
-19
I have tried helper columns with vLookup (can't get away from circular references) and multiple IF/AND/OR statements. I can do SumProduct and SumIf, but I need to know the qty by the individual demand, not just the total. Is this something I can do with a formula or I need to move to VBA?
Subtract the sum of the qty demand(SUMIFS) to that point from the original qty on hand.
=VLOOKUP(B2,H:I,2,0)-SUMIFS($D$1:D1,$B$1:B1,B2)
Note what is and what is not absolute referencing. As the formula is dragged down it will only refer to the values above.
And, as you can see, since we are using conditional formula it does not matter that it is sorted by date instead of by PN and Date:

Excel spreadsheet check two conditions along different rows & columns

Hey I'm really stuck on this one, basically tying to get a result of either 'hired' or 'available' (or 0 & 1 to represent) in B2, of BOTH the two conditions in B1 & A2, looking at the log table A6:B10 of when they are 'hired out'. I've tried VLOOKUP and many IF functions but neither quite work correctly.
One option here, though perhaps not the most graceful, would be to use VLOOKUP with the car and date as the key. The issue here is that there are multiple lookup values, namely the car and the particular date. To get around this, you could create a new column C which contains the concatenated car and date, e.g.
A | B | C | D
6 Car 1 | 03-01-2017 | Car 1 03-01-2017 | 0
7 Car 2 | 03-01-2017 | Car 2 03-01-2017 | 0
8 Car 3 | 04-01-2017 | Car 3 04-01-2017 | 0
9 Car 4 | 05-01-2017 | Car 4 05-01-2017 | 0
10 Car 2 | 06-01-2017 | Car 2 06-01-2017 | 0
To create column C, simply enter the following formula into cell C6 and then copy it down the entire column:
=CONCATENATE(A6, " ", B6)
Now you can use the following VLOOKUP formula in cell B2 to calculate whether a given ride is available on a certain date:
=IFERROR(VLOOKUP(A2&" "&B1,C6:D10,2,FALSE), 1)
Here I have hard-coded in column D the value 0 for every entry, to represent that these are rides which are already hired-out for that particular car and date. If our VLOOKUP formula finds a match, then it means the ride is hired-out. If VLOOKUP does not find a match, it would throw an error, in which case we display 1 to indicate availability.

Excel - Replace blank if only 1 contiguous value

Okay this one is a bit strange to explain, but I have a file like this:
A B
1 | Person
2 | Person test
3 | Record
4 | Record test
5 | Tiger
6 | Scott
7 | Scott test
8 | Scott test
9 | Scott test
As you can see, in column A the first row where a new value starts, column B is blank. What I need is to fill in a placeholder (NULL) value into column B if there is only one contiguous value in column A. So for the above example row 5 only has 1 contiguous value so the result should look like this:
A B
1 | Person
2 | Person test
3 | Record
4 | Record test
5 | Tiger (NULL)
6 | Scott
7 | Scott test
8 | Scott test
9 | Scott test
I tried something like this but doesn't work:
IF(EXACT($A5,$A4)=FALSE AND EXACT($A5,$A6)=FALSE, "(NULL)", $B5)
I just want a formula I can paste all the way down column B. Any suggestions?
=IF(OR(A2=A1,A2=A3),"Test","(NULL)")
Replace Test and (NULL) with the values you want to display.
This checks to see if the AX = A(X-1) or A(X+1). If either of those is true, then it means that AX is contiguous with another row.
I should note that I tested this with Excel 2013.
Also, if you want the formula to use the value already in BX when the rows are contiguous, then you can't do that in the same column.
I'm not sure if that's what you're asking to do, but the formula you tried would have been attempting to do that, creating a circular reference.
You can easily do this in column C. Replace "Test" with BX. Then, if you only want 2 rows in the end, you can copy and paste the values of column C into column B, then delete column C. But, this way you'll lose your formula.
Suppose you have your data like this:
This formula seem to work:
=IF(OR(A2=A1,A2=A3),IF(B2="","",B2),"(NULL)")

using Excel functions to count unique values in one column based on match in other column?

I have an Excel question - is there a method of using functions to count all of the unique values of a column based on matching another column's contents with a particular data interest? For example, suppose I have two columns of data.
A | B
toothbrush | AAA
shampoo | AAA
toothbrush | AAA
toothbrush | BBB
conditioner | CCC
toothbrush | BBB
shampoo | CCC
toothbrush | CCC
toothpaste | CCC
toothpaste | AAA
toothbrush | AAA
shampoo | BBB
I would like to generate, on a separate tab, two columns that display the following information, for example:
C | D
toothbrush | 3
toothpaste | 2
shampoo | 3
conditioner | 1
Column D would be the number of unique customers for each of the 4 products.
Is there a way to do this in Column D using a formula composed of SUM, IF, COUNTIF, etc.?
Thanks in advance and please let me know if I can clarify anything further.
Since others may not be so particular about what readily available tools they decide to avoid, create a PivotTable with "Add this data to the Data Model" with A for ROWS and B for VALUES, then change Count of B to Distinct Count of B.
For the list of unique items, this will do the trick (it will produce blank cells as well):
=IF(COUNTIF(Sheet1!$A$1:A1,Sheet1!A1)>1,"",Sheet1!A1)
Put =IF(COUNTIF(Sheet1!$B$1:B1,Sheet1!B1)>1,"",Sheet1!B1) into column E to produce unique customers.
Finally, put this into column D, making sure to extend it to accommodate the number of rows on sheet1 and pressing CTRL+SHIFT+ENTER to make it an array formula:
{=IF(A1="","",
SUM(IF(COUNTIFS(Sheet1!$A$1:$A$12,A1,Sheet1!$B$1:$B$12,$C$1:$C$12)>0,1,0)))}

Counting word "pairs" in excel between different columns

I'm wondering if it's possible to do this in excel:
Let's say I have these columns:
Column A | Column B
Apple | Red
Apple | Green
Pear | Green
Pear | Green
Is it possible for me to count how many times a set of "pairs" appears.
For example -
I want to count how many times "pear" and "green" appeared in my spreadsheet next to each other (not individually).
So for the above I should get:
Apples + Red appears 1 time
Apples + Green appears 1 time
Pear + Green appears 2 times
I tried using the COUNTIF function, but I don't think it can count a set of pairs like this...
If the above is possible... is it further possible to break down the data by time? For example, we have these columns:
Column A | Column B | Column C
3/7/2013 | Apple | Red
3/7/2013 | Apple | Red
3/8/2013 | Apple | Red
3/8/2013 | Pear | Green
3/8/2013 | Pear | Green
3/9/2013 | Apple | Red
3/9/2013 | Pear Green
If I want to organize the data by day, how can I do this? For example:
I want to display that on 3/7/2013, Apple + Red appeared 2 times, but on 3/8/2013, Pear + Green appeared 2 times and Apple + Red only appeared once.
Is it also possible to organize data by weeks or months this way? (During the month of January, I got 20 Apple + Red "pairs"
Let me know if anything was unclear in what I was asking
Thanks for your help!!!!
Add a new column to your data, which concatenates your data (ideally with delimiters to avoid value clashes) e.g. In Col D1 put formula
=A1&"|"&B1&"|"&C1
Give it a heading of Vals, and then create your pivot table from all the data
As an example I created this sample data which has 2 employees, Fred & Bill and a number of rows for each on 2 days. For 3-Jul, both Fred and Bill appear 3 times, but on 4-Jul Fred appears once and Bill 5 times.
My pivot table shows this result (which is hopefully what you're after)
EDIT :
For your situation, you probably need two extra columns, one called 'Pair Name' which concatenates B & C, and another called 'Pairs' which concatenates A, B & C.
Then in your pivot table you can drag 'Pair Name' into the Column Labels, and 'Pairs' into the Sum of Values.

Resources