Excel If formula - sql

I have two sheets. On sheet 1, column D contains category text values (ie. Events, collateral, etc.) and column I contains dollar values. On Sheet 2, each row is labelled after one of those categories, and the columns are labelled by month.
I would like the cell on Sheet 2 to calculate the following pseudocode:
IF(Sheet1!D20="Events", then add Sheet1!I20 to R9, if not then add 0)
*Where Sheet1!D20:D40 are all categories for December
*Where Sheet1!I20:I40 are individual costs for December
*where Sheet2!R are total costs for December
Yes this is a budget and yes I'm trying to have one sheet show me items we bought divided by month and the other sheet shows me the totals we spent by month in each category.
I hope this is enough info for someone to help me. Thank you in advance.

I'm making a few assumptions about what you want here, but it seems to me that in Sheet2 you will have the categories listed somewhere - perhaps in Col A. So A9 might contain "Events", R1 probably contains "December" and you want R9 to contain the sum of all values in Col I of Sheet1 from rows where Col D contains "Events".
In R9 I would suggest the formula =SUMIF(Sheet1!D:D,A9,I:I). That could be copied up and down Col R to replicate that for other categories.

I'm assuming a couple of things here:
Sheet 1 contains rows that look like this:
Month | Category | Dollars Expense
Let's call those A | B | C for now, even though I know you use D and I.
You want Sheet 2 to look like this:
Row 1: [Category header] | January | February | March | ...
Row 2: Events | [$ spent in January] | [$ spent in Feb] | ...
If that's true, then SUMIFS() will work for you. In our example, we'd use this to return the sum of January Events expenses (Sheet2!B2 in the example):
=SUMIFS(Sheet1!$C:$C,Sheet1!$A:$A,Sheet2!$A2,Sheet1!$B:$B,Sheet2!B$1)
This will sum matches to the column header (month) to the months in sheet 1 and the row lead (category) to 1's the categories column.

Related

Fetching data from row N+M, N+2M,... when N changes

My Google spreadsheet has webpage data imported with IMPORTDATA() on Sheet1. The data of interest are 20 pcs of 12-row deep posts starting at row N (e.g. row 123). Unfortunately, N changes each week or so.
Today I just use 20 hardcoded formulas that copy the data of interest to Sheet2 (e.g. =Sheet1!A123), but each time N changes I need to re-code all these 20 copying formulas on Sheet 2.
I'd prefer a method using e.g. Indexing or Offset formulas, where I would only need to change one "starting index" value when N changes in the webpage. Help would be much appreciated!
EDIT : Hi, thanks for your interest, sorry for delay. So this is the data structure of my Google spreadsheet. The source data can be considered a product list or similar.
Sheet1:
A1 =IMPORTDATA (url)
A2 to A122
A123 product 1 name
A124 product 1 price
A125 to A132... other product 1 data
A133 product 2 name
A134 product 2 price
A135 to A142... other product 2 data
A143 product 3 name....
... and so on up to product 20.
On Sheet2 I then want the following result:
A1 product 1 name
A2 product 1 price
A3 product 2 name
A4 product 2 price.
... and so on.
The problem is that the "uninteresting preamble data" in the beginning changes in length (number of rows) every now and then.

(VBA) Extract and copy and paste column values for specified date range for corresponding row values

I've been stuck on this for a while now. What I need is the title - what I have is:
Sheet 1:
1 billion mostly unnecessary columns.
Column D: Values I need Column F: Column M:
Revenue Names Date
12 John 1/24/2016 2:40:02 AM
15 Sarah 3/2/2016 4:35:17 PM
14 Sarah 7/17/2016 1:50:10 PM
20 Matt 8/20/2012 4:16:12 AM
10 John 11/19/2015 5:04:05 AM
etc. etc.
Current Sheet 2: Pivot Table*
Row Label:
Sarah
Matt
John
etc.
Desired Sheet 2 Pivot Table+*
Row Label: Column __:
Revenue
Sarah 29
Matt 0 *(note: see below, but = 0 because Matts value corresponded to date 2012)
John 22
etc.
The important thing about Sheet 2 is that I would like to tell VBA to find the nearest emptiest column within the sheet, and input the values from Column D from S1 (and sum for duplicates) but only sum and extract values that range from today's date to 11 months prior. Currently I made a module to automatically create a pivot table for the next sheet, but I have wanted to add the above for a while, just stuck.
I'm also assuming I won't have to specify sum if I tell VBA to extract data for corresponding row label names? And I was thinking about putting a Begin Date and End Date cells on Sheet 2 to refer to, or using the TODAY() function somehow for the date, but not sure how to specify to extract and sum values for the date range from today to 11 months prior.
Edit: *Please note this is a watered down version of my current situation, everything is bigger so to avoid confusion, pivots are necessary, but I choose to dilute it for the sake of this issue.
Do you really need a pivot table?
If you dont, just create a new sheet with all the names, set a cell for the starting date you want to consider and do =sumifs
For example
On Sheet2 B1 you put 1/24/2016.
Then on A2 you insert the name (Sarah, for example)
On B2 you put the formula
=Sumifs(Sheet1!D:D,Sheet1!F:F,A2,Sheet1!M:M,">"&B$1)
After that just make a list of name and drag the formula beside every name.
*My excel is in portuguese so maybe the formula needs some other ajustments to work.

Formula help to extract rows meeting multiple criteria

I have a spreadsheet with over 600k rows. I need to extract data based on multiple criteria and grab only the latest change numbers of each.
So an item number may have multiple entries based on quarter start dates and desc codes because it's been revised several times in that quarter but I just want the most recent one (highest change number) and that row returned or marked in a new column to then filter out.
Hope that makes sense.
I have the following columns. Column A (Desc Code) which has 12 different codes in it, then Column B (Item Number several thousand), Column C (Period Begin, Start of the quarters dating back to 1998) and then a Column H (Change Number). I need to basically pull "Each" row containing the highest change number, for each Item Number in each Period it was available for each code.
So basically The change numbers vary depending on how many changes the Item Number had in the quarter.
And each time there was a change there is a change number for each Item Number for Each Desc Code (12 rows for each).
Thanks.
You lost me somewhere near paragraph 4 but let's simplify things. If you just had two columns -- Item Number and Change Number -- and you had a record for each change, you could just use Excel's subtotal feature: at each change in Item Number, show the MAX of Change Number.
Use the same logic for your situation. Create a new column that combines your "category" criteria (item & desc, or item & period, or whatever), sort by it, then subtotal against that new column and return MAX of Change Number.
Edit:
Item Period Change
100 1 1
100 1 2
100 1 3
100 2 1
100 2 2
I'm not sure if this is how your data looks but let's use it as an example (and's lets forget about Desc Code for now). If you want to find the latest change by item and period, create a new column by combining the Item and Period columns. For example, insert a column (C) and use the formula: =A2&"_"&B2. Now your data looks like this:
Item Period I&P Change
100 1 100_1 1
100 1 100_1 2
100 1 100_1 3
100 2 100_2 1
100 2 100_2 2
Now use Excel's subtotal feature (in the Data menu/ribbon, not the worksheet formula). Here's an example of what this looks like:
In your scenario, for the "At each change in" box, pick your new column (C), since that uniquely identifies the category you trying to identify (item AND period). "Use function" = Max. "Add subtotal to" = your Change Number column.
Click [OK] and Excel will add a new row with the maximum Change Number for each.

Using excel VBA to lookup cell value, and return multiple values based on that cell

Sorry for the terrible title, I didn't know how to summarise my problem.
I have a worksheet with a bunch of payments. Each payment is made to an ID number. I have another worksheet with the ID numbers and their breakdown; the percentage of the payment that should be allocated to each pot.
e.g
Client XYZ ,100 payment in worksheet one, has ID 123.
worksheet 2 has,
123 | A | 5%
23 | B | 95% and so on
I would like to be able to produce a third worksheet of the form.
XYZ, 123, A, $5
XYZ, 123, B, $95
So each payment is multiplied by its breakdown and displayed on another sheet along with the rest of the clients info in the adjoining columns.
Even just a start on this would be very helpful. Many thanks.
From reading your question it seems you just want to perform a simple lookup.
If you don't need to use VBA, you can do this easily using excel's VLOOKUP function.

Summarize data in Excel with VBA

I have a table in Excel with dates and values. Every day there were a number of different values.
I want to summarize how many of each value there were every day.
Example:
From this
Date Value
10/1 Blue
10/1 Blue
10/1 Red
11/1 Blue
11/1 Blue
I want to get a new table with something like this:
10/1 11/1
Blue 2 2
Red 1 0
I'm convinced this is possible to do in VBA/Excel. Does anyone have any ideas?
Assuming the first table is in A1 and the second in E1, you could use a formula in F2 like:
=SUM(($A$2:$A$6=F$1)*($B$2:$B$6=$E2))
This is an array formula so you need to validate it by pressing CTRL+SHIFT+ENTER.
A2:A6 is the range with the dates, B2:B6 the range with the colors in your first table.
The first part of the formula says: Retain records where the value in column A is 10/1 ( = F1).
The second part says : Retain records where the value in column B is Blue ( = E2).
The '*' is equivalent to AND.
More about it here: Multiple conditions in excel 2002
The solution was, just as Alex K said, to use the Privot Table function included in Excel.
Thanks for your help!