How to combine vlookup and if else in Excel using formulas - excel

I am trying to update the budget of resources for travelling in sheet 1 with their per day expenses in sheet2. I have to first verify the destination city, and then fetch the expenses of their travel from sheet 2 on the basis of the number of days they are travelling from (mentioned in sheet 1).
So, First the destination should be matched , once we get the row number (from sheet 2), then need to fetch the number of days from sheet 1, and on the basis of the number of days, fetch the expense from sheet 2
Sheet 1
Destination No of Days Total expenses(output)
City 1 1 150
City 2 3.5 200
City 3 2 400
Sheet 2
Destination Day 1 Day 2 Day 3 Day 4
City 2 100 150 175 200
City 1 150 250 350 450
City 3 200 400 600 800
I tried using vlookup, and nested if formula each, but I am not able to fetch the number of days
(IF(A2=Sheet2!$A$2,Sheet2!$B$2,IF(A3=Sheet2!$A$3,Sheet2!$B$3,IF(A4=Sheet2!$B$4,Sheet2!$B$4))))
The outcome is mentioned in the description. The column Total expenses in sheet 1 is the expected output.

Instead of VLookUp, try Index + Match
=INDEX(Sheet2!$B$2:$E$4,MATCH($A2,Sheet2!$A$2:$A$4,0),$B2)

Additionally you can use:
=SUMPRODUCT((Sheet2!$A$2:Sheet1!$A$4=A2)*(Sheet2!$B$1:$E$1="Day " & ROUNDUP(B2,0)),Sheet2!$B$2:$E$4)

Related

Is there a way to dynamically subtracting paid amount from total amount and get a remaining amount in google sheet

This is what I tried.
For below table
A B C
1 Expenses Cost Status
2 Expense1 30000 PAID
3 Expense2 20000
4 Expense3 7500
5 Expense4 520
6 Expense5 2300
7 Expense6 1000
8 Expense7 11618
9 Expense8 7939
10 Expense9 6473
11 Total 87350
12 **Remaining Amount ??**
if a column C cell has "PAID", then Substract Total amount(B11) from the PAID(B2) amount.
=IF(C2:C10="PAID",MINUS(B11,B2:B10),B11)
But this code only subtracts the first PAID amount, do not consider for other cells with PAID
Hoping for help!
You can use the formula SUMIF in it.
Considering that the Total is on column B11 and the Remaining would be on column B12, you can use the formula on B12:
=B11-(SUMIF(C2:C10, "PAID", B2:B10))
The number on the remaining will be going down after each expense gets paid.

Sum a Column if it matches a Criteria in one formula - is it possible?

I have two columns of revenue figures of different brands: Example
US UK
Brand 1 100 0
Brand 2 200 50
Brand 3 100 40
Brand 4 0 20
What I am trying to do is SUM the UK column IF and only if US AND UK are bigger than 0 (Revenue>0), Therefore my output would be 90.
How do I do this in one formula - is it possible?
Thanks
Try SUMIFS() like.
=SUMIFS(C2:C5,B2:B5,">0",C2:C5,">0")

Calculate 3 month Average on the base of CustomerID

I am trying to calculate three month average sales in excel w.r.t customerid in excel. I tried by doing it by AverageIfs function but nothing helped.
A B C
Orderdate sales customerid
5/15/2019 7 1
5/15/2019 48.5 1
4/15/2019 92.94 1
3/17/2019 102.85 1
3/18/2019 49 1
3/18/2019 119.95 1
2/18/2019 58.96 1
1/20/2019 14.6 1
5/16/2019 17 6
4/15/2019 148.5 6
4/12/2019 912.94 6
3/17/2019 102.85 6
9/18/2018 22.34 6
Formula I tried: =AVERAGEIFS(B:B,C:C,C2)
output expected:
customerid average(3 months)
1 49.48
6 359.48
Let's start from today's date and the date 3 months ago (Make it dynamic):
Remember to change the cell format from General to Date. Otherwise, it will show [43563]
Next use the date as part of our filter:
Now you should get the most recent 3 months data:
Copy the filtered data into a new spreadsheet
Copy the filtered data into a new spreadsheet
Copy the filtered data into a new spreadsheet
Next Step: get the distinct customer ID:
You will get this:
Last Step:
Use the function "AVERAGEIF":
Done!

Excel lookup same index different row

I have a formatted table that contains information about areas, including sales for the month (and a heap of other columns containing other details). The table is the basis for graphs and pivot tables.
There is a row per month for each area, e.g.:
A B C D
1 Area Month Sales TwoMonthAverage
2 North 1 400 Manually entered
3 West 1 500 Manually entered
4 South 1 200 Manually entered
5 North 2 200 <calculate??>
6 West 2 200 <calculate??>
7 South 2 200 <calculate??>
8 North 3 100 <calculate??>
9 West 3 900 <calculate??>
10 South 3 600 <calculate??>
Each month, I want to calculate the "2 month average" sales for an area (being the average of the current and previous months).
I need to know how to get the sales for the same area for the previous month. The table rows will not necessarily be in the same area or month order. Needs to work in Excel 2013 and 2010.
Thanks
Blair
You could perhaps use SUMIFS to get the sum of the past 2 months sale:
=SUMIFS($C$2:C5, $A$2:A5, A5, $B$2:B5, ">="&B5-1)
This in D5 will give the sum of values that:
Have values in cells A above and including the current row, and
Have the month above or equal to the current month - 1.
You then only need to divide by 2 to get the 2 month average.

What VBA code options are there to group data into time buckets, copy it to another sheet, and loop for multiple parts (criterion)

I have two files:
File#1 contains customer with demand information. There are only three columns that matter to me:
Part#
Demand Qty
Demand Date
The file has thousands of lines.
File#2 is my own file which has more of an MRP setup:
columns are labeled with dates (weekly)
For each Part: There are the following rows:
Demand
Incoming Inventory
Net Inventory
My general idea was that I could somehow filter both files by part#, then have the code "sumif" the total demand by week, and copy it from the customer file to my file on the corresponding demand row. Then loop this for all part #s.
Part #s are constantly being added/removed in my spreadsheet(as new projects develop, and old ones phase out), so it would be ideal if the code didnt need to be maintenenced as my file is updated with new parts.
It seems like you could use a SUMPRODUCT formula to bring those numbers in without code. This example uses two sheets in the same workbook so you'd have to adjust slightly for different workbooks. In Sheet1 you have three ranges which I've named rngPartNum, rngDemandDate, and rngDemandQty. I used dynamic range names that expand with the data, but you could use cell references that cover a sufficient number of rows. The data looks like this
PartNum Demand Qty DemandDate
1 18 3/28/2011
1 6 3/30/2011
1 6 4/2/2011
2 18 3/28/2011
2 6 3/30/2011
2 6 4/2/2011
2 16 3/28/2011
3 3 3/30/2011
3 15 4/2/2011
3 9 3/28/2011
3 18 3/30/2011
Sheet2 has a week-end date and a part number on each row.
Part Week Demand
1 4/1/2011 24
1 4/8/2011 6
1 4/15/2011 0
2 4/1/2011 40
2 4/8/2011 6
2 4/15/2011 0
3 4/1/2011 30
3 4/8/2011 15
3 4/15/2011 0
The formula in the demand column is this
=SUMPRODUCT((rngPartNum=A2)*(rngDemandDate<=B2)*(rngDemandDate>B2-7)*(rngDemandQty))
That sums everything in rngDemandQty where rngPartNum matches A2 AND rngDemandDate is less than or equal to B2 AND rngDemandDate is greater than a week before B2. As long as you have every part number and enough weeks on your Sheet2, the total should match Sheet1.

Resources