Look for value and subtract if duplicated - excel

I have an Excel table as follows:
Color | Inventory
Blue | 180
Red | 50
Green | 10
I want to look up the inventory of the color that I would require depending which product I'm going to use and then subtract if it was used on a past line, my table would look like this:
Item | Color | Usage | Inventory Left
ABC | Blue | 50 | 130
BCD | Blue | 30 | 100
CDE | Blue | 50 | 50
EFG | Red | 25 | 25
FGH | Red | 10 | 15
GHI | Green | 5 | 5
How could I do it with an Excel formula?
I was thinking in some type of SUMIF with OFFSET but I can't figure it out.

With a layout as shown, please try:
=VLOOKUP(B9,$A$1:$B$6,2,0)-SUMIF(B$1:B9,B9,C$1:C9)
The principle would be the same but a different layout might be more convenient.

Related

Colour all rows with the same colour until value of a cell is not the same as in the previous row anymore

I have the below Excel-table:
| A | B
---------|-----------|---------------
1 | 500 |
2 | 500 |
3 | 500 |
---------|-----------|----------------
4 | 600 |
5 | 600 |
---------------------|----------------
6 | 300 |
---------------------|----------------
7 | 800 |
8 | 800 |
9 | 800 |
---------------------|----------------
10 | 200 |
11 | 200 |
---------------------|----------------
12 | 900 |
---------------------|----------------
13 | 100 |
14 | 100 |
In Column A there a different numbers which can appear multiple times within the rows.
Now I am looking for a conditional formatting that identifies if a number has switched compared to the previous row and if so all the other rows with the same number are coloured in yellow until it switches again.
The result should look like this:
Do you have any idea what kind of conditional formatting I need to achive this?
Select column A
Insert new conditional formatting rule based on formula and use:
If one has Excel O365:
=ISEVEN(COUNT(UNIQUE(A$1:A1)))
Older versions of Excel could use:
=ISEVEN(SUMPRODUCT(1/COUNTIF(A$1:A1,A$1:A1)))

Excel: How to transform multiple columns with headers into 2 columns, one for the data, one for the header

I have a table of products, with multiple QTYs by month. How do I convert this table into a 2-columns list - one for QTY, one for month.
Source Data:
Product | 2019-06 | 2019-07 | 2019-08 | 2019-09 | 2019-10
----------------------------------------------------------
Apple | 10 | 10 | 20 | 25 | 10
Orange | 50 | 100 | 75 | 50 | 100
Desired Output:
Product | QTY | Date
---------------------
Apple | 10 | 2019-06
Apple | 10 | 2019-07
Apple | 20 | 2019-08
Apple | 25 | 2019-09
Apple | 10 | 2019-10
Orange | 50 | 2019-06
Orange | 100 | 2019-07
Orange | 75 | 2019-08
Orange | 50 | 2019-09
Orange | 100 | 2019-10
Use Power Query a free MS add-in since 2010, and distributed with Excel 2016+ as Get&Transform.
In the Power Query UI, select the first column and then Unpivot other columns. Rename the columns as needed.
Also see my answer to Resorting Table using Array for more details

Count distinct occurrences and averages in a column based on identifiers in another column

In MS Excel, I want to count the number of distinct categories (ignoring a specific item) based on a different column. Also, I want to find the average and the max for the same selection. This is the data:
+--------+-----------+-------+
| Person | idea | score |
+--------+-----------+-------+
| George | vacuum | 9 |
| George | box | 6 |
| George | x | 1 |
| Joe | scoop | 4 |
| Joe | x | 1 |
| Joe | x | 1 |
| Joe | scoop | 4 |
| Joe | gear | 7 |
| Mike | harvester | 10 |
| Mike | gear | 7 |
| Mike | box | 6 |
+--------+-----------+-------+
The result should be the following:
+--------+----------------+------------+-----------+
| Person | distinct ideas | Avg. score | Max score |
+--------+----------------+------------+-----------+
| George | 2 | 5.3 | 9 |
| Joe | 2 | 3.4 | 7 |
| Mike | 3 | 7.7 | 10 |
+--------+----------------+------------+-----------+
Because Joe has two "scoop" and one "gear" idea, and I want to ignore the "x" items.
I reluctantly gave up and did it manually for each person, e.g., this is for the first person:
SUM(IF(FREQUENCY(MATCH(B2:B4,B2:B4,0),MATCH(B2:B4,B2:B4,0))>0,1))-IF(COUNTIF(B2:B4,"x")>0,1,0)
Doesn't Excel have functions to return a range instead of a value? If I could select the range based on the name of the person in the first columns, I could count distinct occurrences or find the average in another column.
Add a 4th column and label it Distinct Ideas
If your table starts in A1, then:
EDIT: Formula changed to exclude "x". Screen shot also changed
D2: =IF(TRIM($B2)="x",0,IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1))
and fill down.
Then construct a Pivot table
Person to Row Labels
Distinct Ideas to Values area
score to Values and select to Average
Score to Values area and Select Max
Format as desired. Here is one result:

Can I populate a column with conditional data while omitting empty rows or possibly autosort?

In one spreadsheet document, file.xlsx, I have 2 sheets. Sheet1 has the editable fields. Sheet 2's sole purpose is to read the data from Sheet1.
The point is to keep track of inventory and easily display items needed to be ordered.
Sheet1 'column a' is item number for ordering
Sheet1 'column b' is the number I have on hand
Sheet1 'column c' is the formula cell to find the number needed to be ordered
It looks something like this:
Document1:sheet1
A | B | C |
1 |txt1 | 1 | =10-b1 |
2 |txt2 | 0 | =10-b2 |
3 |txt3 | 13 | =10-b3 |
4 |txt4 | 5 | =10-b3 |
5 |txt5 | 2 | =10-b4 |
There is some if statement conditional formatting in the "C" column to check if the "B" column has a value HIGHER than 10 and if it hits true then the corresponding C cell is blank but for space, i'm summarizing here
Document1:sheet2
A | B |
1 |=if(sheet1!C1>0,Sheet1!A1,"") |=if(sheet1!C1>0,Sheet1!C1,"") |
2 |=if(sheet1!C2>0,Sheet1!A2,"") |=if(sheet1!C1>0,Sheet1!C2,"") |
3 |=if(sheet1!C3>0,Sheet1!A3,"") |=if(sheet1!C1>0,Sheet1!C3,"") |
4 |=if(sheet1!C4>0,Sheet1!A4,"") |=if(sheet1!C1>0,Sheet1!C4,"") |
5 |=if(sheet1!C5>0,Sheet1!A5,"") |=if(sheet1!C1>0,Sheet1!C5,"") |
If an item isn't to be ordered because stock is high, it doesn't show up in the list. This is ok. It looks like this:
Document1:sheet2
A | B |
1 | txt1 | 9 |
2 | txt2 | 10 |
3 | | |
4 | txt4 | 9 |
5 | | |
What I would like to see is:
Document1:sheet2
A | B |
1 | txt1 | 9 |
2 | txt2 | 10 |
3 | txt4 | 9 |
4 | | |
5 | | |
For 5 Items in the example, it doesn't seem that annoying, but in actuality I have 1200 potential rows and it varies between 200 to 800 actually populated each time i conduct inventory. The whole point is to have one continuous section of rows that I can select and print. Maybe some way of autosorting and placing the empty ones on the bottom?
I've taught myself excel. I don't know the advanced tricks and things.
I'm a typically a programmer but I've been tasked with this project and the guys upstairs want me to do it in excel.
i've overcomplicated this, to the max.
a simple sort putting the empty's at the bottom is the resolution.
not quite as automated as i'd like
but
it works.

Excel Calculations and VBA

In the following Excel spreadsheet, I need to make the following calculations:
Input Color Selected Output
------- -------------- --------
40 red 40x18
40 blue 40x12
40 green 40x16
40 yellow 40x13
39 red 39x18
28 blue 28x12
33 green 33x16
25 yellow 25x13
My question is, how can I assign values to the colors being selected using Java?
It sounds like you want to be doing something like this... "Countif cell color is red". That is, you mean to apply different multipliers based on the format of a cell. See also "Color Functions In Excel".
But to be honest, the best thing to do is to create a new column that contains the semantics of the information you are trying to represent using formatting and use THAT for your conditional expression instead. Make a column that contains the information contained in the "color" formatting and use that.
You could have a separate table with colors and numbers:
| F | G |
---|---------|-------|--
1 | red | 18 |
2 | blue | 12 |
3 | green | 16 |
. | ... | .. |
And then use the table in your calculation:
| A | B | C |
---|-------|-----------|-----------------------------------|--
1 | 40 | red | =A1*VLOOKUP(B1,$F$1:$G$100,2,0) |
2 | 40 | blue | =A2*VLOOKUP(B2,$F$1:$G$100,2,0) |
. | .. | ... | ... |

Resources