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

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

Related

DAX returning value based on SUM of multiple rows in other table

Good evening all!!
Here's a fun one. I've been pouring through some other posts and it feels like there are many permutations of this scenario but none that span tables, so I'm looking for some input.
Consider the following:
Table A has two fields: ID and TYPE. TYPE will be our value to populate.
ID Type
1
2
3
Table B has two fields: ASSOCIATED ID and HOURS.
Associated ID Hours
1 24
1 0
2 10
2 38
3 50
3 25
The requirement is to return a value of "LESS THAN 25" or "GREATER THAN 25" for TYPE in TABLE A based on the SUM of the HOURS in TABLE B for the ASSOCIATED ID. Ex: ASSOCIATED ID "1" in TABLE has value 24 and 0 for a sum of 24, returning "LESS THAN 25" for TYPE in item ID 1 in TABLE A.
Any and all suggestions will be attempted, thank you so much to the community for taking a look.
Make sure you have a relationship between the two tables by using the ID. Then enter this formula into a column in the ID table:
Type:=if(calculate(sum(TableB[Hours]))>25,"25 or More","Less than 25")
Try this one on 1-TYPE: (I am considering A1 Cell as the beginning of your table for both table, just place the real position)
=IF(SUMIF(TableB!$A$2:$A$7,"="&A2,TableB!$B$2:$B$7)>=25,"GREATER THAN 25","LESS THAN 25")
Then drag it down.

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.

Aggregating records with two main IDs in [VBA macro]

I want to make a macro in Excel that summarizes data from rows that match a composite ID generated from 2 ID columns. In my excel sheet, each row has 2 main ID columns: ID_1 is the main key, and ID_2 is a secondary key from which I only care about the first 2 letters (Which I have gotten using LEFT). I want to group rows with the same ID_1 and first 2 letters of ID_2 and report the SUM of the value, count, and sum columns.
In the example picture below, I want to turn the data in columns A:J into the data in columns M:V
So, with this example -> We have 6 records 1015 (ID_1) with 3 different ID_2 (AB, AZ, AE). I want to sum them up to a one cell each (1015 AB ; 1015 AZ ;1015 AE) with values which each record had (there is 3 records: 1015 AB with VALUE of 2,3,4 so in result I want to get just one row 1015 AB 9(sum of value) 4(sum of count) 17 (sum of(value * count)). It's important to see that this 17 dosn't come from 9 * 4. It's =sum(I4:I6) (but it may be spread out like in 1200 FF example below! I am still trying to sort them both at one time, but I cant get past it..)
Add a helper column in D to combine the ID_1 and the first 2 characters of ID_2. =A4 & LEFT(C4,2). Copy that down then go to L4 and type in:
=+INDEX($D$4:$D$25,MATCH(0,COUNTIF(L$3:L3,$D$4:$D$25),0)
and hold down Ctrl + Shift + Enter to make it an array function. Copy down to get a list of unique combinations, and then split these values into the separate columns.
Finally to pull in the numbers, put this in Q4:
=SUMIFS(E$4:E$25,$A$4:$A$25,M4,$C$4:$C$25,O4 & "*")
and then copy down and across.

How to get the latest date with same ID in Excel

I want to Get the Record with the most recent date as same ID's have different dates. Need to pick the BOLD values. Below is the sample data, As original data consist of 10000 records.
ID Date
5 25/02/2014
5 7/02/2014
5 6/12/2013
5 25/11/2013
5 4/11/2013
3 5/05/2013
3 19/02/2013
3 12/11/2012
1 7/03/2013
2 24/09/2012
2 7/09/2012
4 6/12/2013
4 19/04/2013
4 31/03/2013
4 26/08/2012
What I would do is in column B use this formula and fill down
=LEFT(A1,1)
in column C
=DATEVALUE(MID(A1,2,99))
then filter column B to a specific value of interest and sort by column C to order these values by date.
Edit: Even easier do a two level sort by B then by C newest to oldest. The first B in the list is newest.
Do you need a programmatic / formula only solution or can you use a workflow? If a workflow will work, then how about this:
Construct a pivot table of your data
Make the Rows Labels the ID
Make the Values Max of Date
The resulting table is your answer.
Row Labels Max of Date
1 07/03/13
2 24/09/12
3 05/05/13
4 06/12/13
5 25/02/14

Create a excel formula that combines 2 tables

I have 2 tables. Table 1 has employees and Table 2 has codes and their values.
For each employee row in Table 1 by looking up the last 5 characters and matching it Table 2 Column header,I want to insert new rows with all of the Table 2 Code rows and correspondnig "Plan" column value.
For Example, in Table1 1st row EE_Plan1, the last 5 characters "Plan1" should match the 2nd column in Table2, get the plan values (123,879) and insert new code rows as shown below in END RESULT.
Really appreciate any help with creating a formula. Thank you!!
TABLE1
Employee
--------
EE_Plan1
EE_Plan2
EE_Plan3
TABLE2
Code Plan1 Plan2 Plan3
---- ----- ----- -----
DND 123 456 jgh
ABC 879 978 ajs
END RESULT
Employee Code Plan Desc
-------- ---- ---------
EE_Plan1 DND 123
EE_Plan1 ABC 879
EE_Plan2 DND 456
EE_Plan2 ABC 978
EE_Plan3 DND jgh
EE_Plan3 ABC ajs
Vlookups are your friend here. Use a VLOOKUP to locate the corresponding value on the other table and place a cell's value in a different table by reference of Employee. Sorting the sheet before a lookup can help tremendously and set Range Looup to False.
=VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
For returning multiple values see this article from Microsoft.

Resources