My single dataset (generated from a large spreadsheet) is split into multiple tables. The relevant information is the dates and a numerical value assigned to them.
The data is organized as such on each table:
Start Date | End Date | Return Value
A1 | B1 | C1
A2 | B2 | C2
A3 | B2 | C3
The start and end dates are always quarter start and quarter end dates. The value C is always numeric. Each table represents a specific account. Some of these tables don't start until later dates (So Table 4 might have a start date equal to A3, for example).
I would like to group up these tables so the final report is organized as such:
Date range A1 - B1
Table1.C1 | calc(Table1.C1)
Table2.C1 | calc(Table2.C1)
Table3.C1 | calc(Table3.C1)
etc.
And on each detail line where TableX.CY is listed, perform relevant calculations using formulas.
The formulas I've already figured out and gotten sorted, but I'm lost at the best way to refer to each table without creating brand new formulas per table. IE, I don't want to create calcTable1(Table1.C1), calcTable2(Table2.C1), and so on, since there are over 40 tables in this.
How can I link these tables together so that the result set that CR is working with can be easily organized to produce this sort of report?
You can link tables in the Database Fields -> Database Expert -> Links tab.
If you wish to perform these calculations via SQL before they even reach the report, you can do so in the Database Expert by using the Add Command option to write your on SQL formulas.
Otherwise you want to group based on a date range. So you should probably first create a formula to return the format Date range A1 - B1. Then create a group based on that formula you just made.
To add a group, go to Insert -> Group and select your formula as the subject of the Grouped By field.
Related
I have a basic cash flow Google Sheet that I use to track my personal finances, cash in and out of my checking account.
Here's basically what it looks like:
Column A Column B Column C
Row 1 | Water bill | -50.00 | 400.00
Row 2 | Credit card | -300.00 | 100.00 >> the formula here is =sum(C1,B2)
Row 3 | Paycheck | 2000.00 | 2100.00 >> the formula here is =sum(C2,B3)
I project this out a full year. Anytime I want to add a row, I have to manually apply the formula in column C, and then I also have to fix the formula in the row just below it, which then fixes the problem for the rest of the sheet.
In Google Sheets, Is there a way for me to hard-code a formula for Column C that would allow me to insert a new row and always have it math perfectly without having to manually add the formula, and fix the formula in the row below it?
Let me know if there would be an easier way to do this by making fundamental changes to how it's setup - this is just how I've done it for so long, and I'm looking for a way to automate this going forward.
I've heard array formula might be helpful, but I'm not sure how to set it up.
There are many kinds of ArrayFormulas and LAMBDA functions. I suggest you look into them for different cases and uses. There is one kind in particular that would serve to your purposes:
=SCAN(0,B2:B,LAMBDA(a,v,a+v))
If you put this in C2 you'll have a cumulative sum row by row. Try it and let me know!
If you want to hide the results if column B is empty you can use another ARRAYFORMULA to check if B is empty it returns empty, either way returns the SCAN result:
=ARRAYFORMULA(IF(B2:B="","",SCAN(0,B2:B,LAMBDA(a,v,a+v))))
If you need to insert a new row in between then it's quite tedious as it will mess up the formulas below it, but if you just keep appending a new entry on the bottom row, then the formula will smartly mimic the behavior above it. Then you can simply do this:
Select the current last row, then click the small dot at the end and drag it down to as much as you want
OR, Ctrl+C (Copy) the last row, then select as much empty rows beneath it as you want, then Ctrl+V (Paste)
I'm having trouble getting google sheets to do what I want it to do.
I have a form that adds new rows into a google sheets spreadsheet
The entries are then further manipulated in new columns that don't correlate to the google form.
I wanted 3 columns of deductions to be subtracted from 1 column being a daily intake
a. example:
[] gForm:Daily bank(A) | gForm:Credit Cards(B) | gForm:Tip outs(C) | gForm:Total Cash(D) | Column E
1 30 30 40 200 100
2
3
I want each line in Column E to automatically populate the code in each new row, that takes column D and subtracts A:C and spits out the difference in Column E.
code example idea: =sum(D:D-sum(A:C))
I made this an Array formula: Below
=ARRAYFORMULA(IF(ROW(G:G)=1, "Total Taxable Cash", IF(ISBLANK(F:F), "", ArrayFormula(F:F-(sum(C2:E2))))))
PROBLEM is that it takes every cell in colums A:C and then subtracts each row in Column D to spit out incorrect answers in Column E.
Does anyone know how to code this so that it adds the code automatically to each new row but also calculate each row individually and not as columns.
Please help me, thank you all.
Michael, your examples in your post are inconsistent. You reference A:D and SUM(C:D), but then your formula example uses G, F and SUM(C2:E). I'll assume that your formula is correct and your example data above it is wrong.
I also don't clearly understand your goal. But at a guess, try this:
=ArrayFormula(IF(ROW(A:A)=1, "Total Taxable Cash", IF(F:F="",,F:F-(C:C+D:D+E:E))))
I've written out some inefficiency and redundancy. But the key change is just swapping your SUM(C2:E2) with (C:C+D:D+E:E).
I created a pivot table in googlesheets, and it returns results that look like:
first | second | CountOf3
--------------------------
thing | value | 23
| newVal | 3
| cool | 34
that | value | 234
otherThing | cool | 4
| newVal | 345
And I want to filter out results with just one resulting row for the item in the first column.
So in this example, that would be the row: that | value | 234.
I would like the filter to remove that row, and leave the remaining rows. This is a pivot table in a 2nd sheet that updates when Sheet1 changes.
I have been trying all day, and have not been able to come up with a solution. I was hoping there would be some sort of filter, or spreadsheet formula to do this. I've tried multiple combinations of filters, but nothing seems to work - I'm starting to wonder if this is even possible.
It isn't pretty, but a brute force way is to have a check column beside your pivot table, with this formula on the first data row, ie beside "thing | value | 23".
It flags each row where the subsequent cell in column D is not blank. Then use a query (or filter) to list only the output rows you want. Note that you would hide the columns or rows with the actual (unfiltered) pivot output.
This is the simplest version, to see the logic:
=AND(LEN(D3),LEN(D4))
which results in a TRUE value for pivot chart rows that only have one value.
A more elegant version is an arrayformula, adds the header lable, and uses "Skip" as the flag for which rows to filter out.
={"Better Check";ARRAYFORMULA(IF(LEN(D3:D998)*LEN(D4:D999)*LEN(E3:E998),"Skip",))}
Note that this formula allows for a pivot table result effectively to the bottom of the sheet, but it does have a finite range, due to the constraint of checking two rows at once. It could be enhanced by using a COUNTA on the third data column to measure the exact length of the pivot table results and control the range dynamically, Like this:
={"Better Check";
ARRAYFORMULA( IF( LEN(INDIRECT("D3:D" & (COUNTA(F$3:F)+ROW(F$2)))) *
LEN(INDIRECT("D4:D" & (COUNTA(F$3:F)+1+ROW(F$2)))),
"Skip",))}
Let us know if this helps at all.
Let's say that we have two columns on a sheet:
Name Room
-------------
Steve A1
Jill A1
Sam A1
Steve A2
...
Lisa A10
Sally A11
Jim A11
My actual dataset has up to a hundred of these rooms.
The issue I'm running into is with pivot tables. When I want to get a list of rooms and the count (counta is the one I'm using) it works, but the order is not what I wanted. It comes out as:
Room Count
--------------
A1 3
A10 1
A11 2
...
A2 1
I guess I can kind of see why it would be doing that. I'd much rather have it list it out in order. A1, A2, A3... A10, A11, A12, etc.
Is there an easy way to do this without some sort of data manipulation?
An "easy" way to do this without "data manipulation" is to copy the PT, Paste special, Paste values only and then drag the relevant rows (presumably at most only 8) to where you want them. The easiest way is probably with "data manipulation", for example:
=if(len(A1)=2,SUBSTITUTE(A1,"A","A0"),A1)
(Though in you case, whichever column would be the right one, it would not be ColumnA.)
I suggest you transform the string elements into number values using a lookup table.
I've created a sample spreadsheet here.
The input data in the 'input' sheet has the keys as you described.
The next sheet is the "lookup table" to translate each key into a value number. I suggest choosing large numbers to leave room for future intermediate numbers if needed
Pivot 1 is based on the original data as you described
Pivot 2 is based on the re-calculated room name using the lookup table.
The formula I used for the re-calculation is:
=VALUE(SUBSTITUTE(A2,MID(A2,1,1),VLOOKUP(MID(A2,1,1),'Lookup table'!$A$1:$B$2,2)))
I was a little lazy with the string lookup in the original name (MID), assuming your string is the first character and is 1 character long. This can be mended specifically with pattern matching.
Below is an example of a table I have, what I am trying to do is get the value in the value column for a specific criteria based on the last occurrence (not including today's date).
So in the example below I want to find the value for the last occurrence of 'A', which is 12.
I think this can be done using an Index-Match, I just can't get my head around it though.
For example
Todays Date: 15/12/2013
---------------------------------|
|Date | Criteria | Value
|--------------------------------|
|12/11/2013 | A | 3 |
|16/11/2013 | B | 6 |
|27/11/2013 | C | 7 |
|3/12/2013 | A | 12 |
|5/12/2013 | B | 8 |
|15/12/2013 | A | |
----------------------------------
EDIT:
I would also like to add that this formula will be in a different sheet to the table above. The sheet reference in the formula also needs to be dynamic, it will draw the sheet name from another cell.
I would use this formula:
=index(C:C,max(arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0))),1)
This formula assumes that your data is in the columns A,B,C and for every "A" value in the Criteria column, the Date is different. (If that's not the case, then this formula won't work, see below.
Let's look the formula inside from outside:
filter(A:A,B:B="A",C:C<>"") - This will result with the dates where there is an "A" in the Criteria column, and where the Value column is not empty.
arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0)) - In this step we basically find the row number in which those dates are present. The match function will search for the dates (counted in step 1). The arrayformula is needed because there will be more results.
max(arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0))) - This will find the maximum row number (The maximum row number which contains an "A" in the Criteria column)
index(C:C,max(arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0))),1) - Finally, we use the INDEX function to navigate to the value, which has the maximum row number.
Now, if you want this formula to work on another sheet, you should write, instead of for example:
=index(C:C,... => =index(Data!C:C,...
Assuming that your data is in your Data worksheet.
If you want to this sheet to be dynamic, it's a bit tricky. Let's assume, that you're getting the value of the sheet name from the G1 cell. Then you should write:
=index(indirect(concatenate(G1,"!C:C")),...
This is not so pretty as you should do this for every occasion when it occurs in that long formula (described earlier). Instead you can do some pre-work.
Let's write this to your H1 cell: =concatenate(G1,"!C:C") - If in the G1 cell the sheet name is "Data", then the H1 cell should contain: Data!C:C, similarly you can add to the
H2 cell: =concatenate(G1,"!A:A"),
H3 cell: =concatenate(G1,"!B:B")
Now you can write (and that's the final answer for your question I think):
=index(indirect(H1),max(arrayformula(match(filter(indirect(H2),indirect(H3)="A",indirect(H1)<>""),indirect(H2),0))),1) - where H1,H2,H3 will reference to your Data sheet's columns.
I hope it helps.
Use the following formula to accomplish that.
Formula
=QUERY(
B1:D6, // data
"SELECT D // select
WHERE // where clause
C = 'A' AND // first criterium
D IS NOT NULL // second criterium
ORDER BY B DESC // order by
LIMIT 1, // limit
0" // headers
)
for copy/paste
=QUERY(B1:D6, "SELECT D WHERE C = 'A' AND D IS NOT NULL ORDER BY B DESC LIMIT 1", 0)
Explained
The clue to the formula is the usage of the ORDER BY and the LIMIT options within the QUERY formula. The WHERE clauses will prepare the result in the first place. Next, column B (the dates) is ordered descendingly (highest first). The LIMIT option sets the amount of rows to be displayed at 1.
Example
I've created an example file for you: Lookup value based on latest matching Criteria
I appreciate this is a slightly old question, but there is a way that I achieved the goal of filtering an array which I found both more conceptually straightforward, and also more generally applicable than the other answers I have seen, using vlookup's definitional ability to pick the first matching value in an array.
PROBLEM, RESTATED:
Assuming sample data:
A...B...C...D...E, created by a google form
A is the form entry date
B, C and D are entries from a list (let's assume they are e.g. product name, geography, and sales date)
E is the value
If a new value is entered for a particular product, in a geography, on a date, then I want this to be used in preference to the older version of that same data.
SOLUTION:
If, in your form, you create three new columns:
F Unique test
G Test cells combined
H Unique cells
Then in column G, you create a combination of all the cells you want to test on (in this case B, C and E)
cell G2: "=arrayformula(B2:B & char(9) & C2:C & char(9) & D2:D)"
The next column is a restatement of the cells you want to filter based on (in this case the date in A)
cell H2: "=arrayformula(A2:A)"
And then finally in column F we actually undertake the test:
cell F2: "=arrayformula(A2:A=vlookup(G2:G,sort({G2:H},2,false),2,false))"
Breaking that down, the vlookup (vlookup(G2:G,[RANGE],2,false) compares the data in G2, G3...Gn with a [RANGE], which is a virtual array consisting of two columns, G and H, pre-sorted according to cell H in descending order.
i.e. For any unique value of G (the combination of test data) the vlookup will return the largest value of H
The last part is a simple comparison to the original data (A2, A3... An) to return TRUE or FALSE based on whether it is the latest version of the unique value.
A final step if needed would be to create a new sheet with "=filter('Form Responses 1'!A:E,'Form Responses 1'F:F=TRUE) to recreate the data without the older versions.
Hope this helps.