array formula with dates - arrays

I have four columns of dates(A,B,C,D),I want to excel verify if each period of "period 2" intersects ALL "period 1" from 1,2,3.....
For example 20-28/01/2016 intersects 01-24/01/2016 AND 25/01-03/02/2016. The answer in this case in column E must be "wrong".
I think this have to be an array because in a cell must be verified an entire column. If it could be done without array I would be very happy, because array slow time calculation very much down on my computer .
_________________________________________________________________
| A | B | C | D | E |
| period 1 | period 2 | |
1 |01/01/2016|24/01/2016|20/01/2016|28/01/2016| "wrong" |
2 |25/01/2016|03/02/2016|04/02/2016|10/02/2016| "ok" |
3 |

Related

ArrayFormula in google sheets SUM if values match criteria

Ok, so I've been stuck on this for a while now trying to create an array formula that will do the following:
Let's pretend the data I'm working with appears as such:
SHEET 1 SHEET 2
| A | B | C | D | E | F | A | B |
1 | Up | Down | Down | Up | Down | 1 | Red | $50 |
2 | Red | Green| White| Black | Blue | 2 | Green | $100 |
3 | $50 | $200 | $15 | Hidden| | 3 | White | $10 |
4 | | $200 | | Hidden| $100 | 4 | Black | $70 |
5 | $50 | $200 | $15 | Hidden| | 5 | Blue | $100 |
Using that data, I need a formula in column F (that I can copy and paste for subsequent cells in the column).
My actual sheet has about 45 columns across and about 25 rows down with sensitive financial information, so I'm using pretend data above on a smaller scale.
So the formula should look something like this (this would be posted in column F of Sheet 1). It needs to check if $A$1:$E$1="Up" (disregard anything that is not "Up") in addition, IF that array = "up" then check to make sure $A3:$E3>$0 (I intend to exclude blank values and "hidden" values), then IF those 2 criteria are met, then return the corresponding value from $A$2:$E$2 and use that as a search key in a lookup formula (HLookup, Vlookup, offset+match, etc). So for example, the Formula in F3 would match those 2 criteria (which would be A2 [red] and then sum together all of the matching values - in this case, there is only 1 matching value, but usually there will be 3-5).
Attempt 1:
=ArrayFormula(SUM(OFFSET('Sheet 2'!$B$1,MATCH(IF(AND($A$1:$E$1="Up",$A3:$E3>"$0"),$A$2:$E$2,""),'Sheet 2'!$A$1:$A$5,0),0)))
Attempt 2:
=ArrayFormula(SUM(IF(AND($A$1:$E$1="Up",$A3:$E3>"$0"),OFFSET('Sheet 2'!$B$1,MATCH($A$2:$E$2,'Sheet 2'!$A$1:$A$5,0),0),"")))
My first attempt attempts to create an array for the Match search key that uses the IF statements to determine the results to be used in the match condition (In the example above, the only result would be "Red", but in the actual sheet, it could be an array like "Red, Blue, Yellow").
My second attempt attempts to first determine which cells we are using (based on IF conditions), then if the cell matches the IF then we will OFFSET the particular cell.
The errors I have noticed is that match doesn't seem to like my array in the search key. The first attempt results with an error saying it cannot find " in the range. (I guess I don't understand why it was searching for that...?). The 2nd attempt seems to fail because it uses the ENTIRE range ($A$2:$E$2), instead of only the cells that match the criteria.
I have tried such things as: VLookUp, HLookUp, LookUp (but it is not a sorted list). I've tried some other weird tactics, but non seem to give me what I need.
So far, the best I have come up with is:
=ArrayFormula(SUM(IF($A$1:$E$1="Up",IF($A3:$E3>"$0",0,OFFSET('Sheet 2'!$B$1,MATCH($A2:$E2,'Sheet 2'!$A$1:$A$5,0),0)),0)))
In my sheet, it found 3 cells that matched the criteria, but instead of adding Cell 1 value, Cell 2 value, and Cell 3 value, it just added Cell 1 value 3 times. So it seems it was only using $A2 (the first option in the range for the match search key) and repeated it for every cell that matched.
I have also tried to include the Filter function (instead of IF) to eliminate cells that do not have "up" as their value ($A$1:$E$1).
Use SUMPRODUCT:
=SUMPRODUCT(($A$1:$E$1="Up")*(VLOOKUP($A$2:$E$2,'Sheet 2'!$A$1:$B$5,2,FALSE))*($A3:$E3>0)*(ISNUMBER($A3:$E3)))

Google spreadsheets query range get item to the right

I am trying to get data from a "flexible" sheet.
The idea is to add in a row a string, and next to it add a formula that from another sheet, it looks up the string and returns the cell just at the right.
Example:
Data Sheet: DataCollection
| | A | B | C | D |
| 1 | Pepper | 2 | Sugar | 5 |
| 2 | Carbon | 3 | Toy | 34 |
so if in my other sheet, the "Summary" I add to A1 Sugar I would like to see in A2 a 5.
What I have tried so far
VLOOKUP function
=VLOOKUP(A1,'DataCollection'!A2:B&'DataCollection'!C2:D,1,false)
didn't work! I keep receiving a parse formula error.
QUERY function
=QUERY(DataCollection, "SELECT B WHERE A = A1")
that does not work either, I need many different Named Ranges and add a different query for each of them.
Here is a test spreadsheet in case it explains better that my wall of text:
https://docs.google.com/spreadsheets/d/15L5nPGfZ8OXS5Rhl3PdIVhtF7D3QzerkARskflDiJL4/edit?usp=sharing
you almost had it. try:
=VLOOKUP(A1, {'DataCollection'!A2:B; 'DataCollection'!C2:D}, 2, 0)
for an array use:
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A, {'DataCollection'!A2:B; 'DataCollection'!C2:D}, 2, 0)))

How to make a loop or "sum" formula in Microsoft Excel?

Say that I gain +5 coins from every room I complete. What I'm trying to do is to make a formula in Excel that gets the total coins I've gotten from the first room to the 100th room.
With C++, I guess it would be something like:
while (lastRoom > 0)
{
totalCoins = lastRoom*5;
lastRoom--;
}
totalCoins, being an array so that you can just output the sum of the array.
So if ever, how do you put this code in excel and get it to work? Or is there any other way to get the total coins?
The are infinite solutions.
One is to build a table like this:
+---+----------+---------------+
| | A | B |
+---+----------+---------------+
| 1 | UserID | RoomCompleted |
| 2 | User 001 | Room 1 |
| 3 | User 002 | Room 1 |
| 4 | User 002 | Room 2 |
| 5 | User 002 | Room 3 |
+---+----------+---------------+
them pivot the spreadsheet to get the following:
+---+----------+-----------------------+
| | A | B |
+---+----------+-----------------------+
| 1 | User | Total Rooms completed |
| 2 | User 001 | 1 |
| 3 | User 002 | 3 |
+---+----------+-----------------------+
where you have the number of completed rooms for each users. You can now multiplicate the number per 5 as a simple formula or (better) as a calculated filed of the pivot.
If I understand you correctly you shouldn't need any special code, just a formula:
=(C2-A2+1)*B2
Where C2 = Nth room, A2 = Previous Room, and B2 = coin reward. You can change A2, B2, or C2 and the formula in D2 will output the result.
You can use the formula for sum of integers less than n: (n - 1)*(n / 2), then multiply it by coin count so you will get something like: 5 * (n - 1)*(n / 2). Then you just hook it up to your table.
Hope it helps

Django QuerySet - Multiple Order By when there is a single field per record

I am accessing an API where the number of fields can change at any time, but I must store and display the data as a table. Therefore, each record from the API is stored as a single record per field. My problem is that I am having trouble working out how I would order by multiple columns at a time. Putting all of the data into a 2D array (list of lists) before sorting is not a viable option as the number of records could be too large to feasibly hold in memory.
I've put together a simple example to explain. If anyone has an idea on how to overcome the problem, or how I could redesign my approach, I'd be very grateful.
| record_id | field | data |
| 1 | x | 2 |
| 1 | y | 1 |
| 1 | z | 3 |
| 2 | x | 30 |
| 2 | y | 42 |
| 2 | z | 7 |
| 3 | x | 53 |
| 3 | y | 2 |
| 3 | z | 7 |
If ordering by fields 'z' then 'x' (both ascending), the record order would be 1,2,3
If ordering by fields 'z' then 'y' (both ascending), the record order would be 1,3,2
I am using models in django to store and I am using QuerySets to retrieve the data. I don't have any control over the API or database from which I am originally accessing the data.
After a fair amount of research I realised I was going about this all wrong - I am now using an hstore field in postgres and django-hstore to utilise it, for a schema-less approach. I now have a single row per original record and I can order_by after casting the required field in an 'extra' method.

Conditional SUM using multiple tables in EXCEL

I have a table that I'm trying to populate based on the values of two reference tables.
I have various different projects 'Type 1', 'Type 2' etc. that each run for 4 months and cost different amounts depending on when in their life cycle they are. These costings are shown in Ref Table 1.
Ref Table 1
Month | a | b | c | d
---------------------------------
Type 1 | 1 | 2 | 3 | 4
Type 2 | 10 | 20 | 30 | 40
Type 3 | 100 | 200 | 300 | 400
Ref Table 2 shows my schedule of projects for the next 3 months. With 2 new ones starting in Jan, one being a Type 1 and the other being a Type 2. In Feb, I'll have 4 projects, the first two entering their second month and two new ones start, but this time a Type 1 and a Type 3.
Ref table 2
Date | Jan | Feb | Mar
--------------------------
Type 1 | a | b | c
Type 1 | | a | b
Type 2 | a | b | c
Type 2 | | | a
Type 3 | | a | b
I'd like to create a table which calculates the total costs spent per project type each month. Example results are shown below in Results table.
Results
Date | Jan | Feb | Mar
-------------------------------
Type 1 | 1 | 3 | 5
Type 2 | 10 | 20 | 40
Type 3 | 0 | 100 | 200
I tried doing it with an array formula:
Res!b2 = {sum(if((Res!A2 = Ref2!A2:A6) * (Res!A2 = Ref1!A2:A4) * (Ref2!B2:D6 = Ref1!B1:D1), Ref!B2:E4))}
However it doesn't work and I believe that it's because of the third condition trying to compare a vector with another vector rather than a single value.
Does anyone have any idea how I can do this? Happy to use arrays, index, match, vector, lookups but NOT VBA.
Thanks
Assuming that months in results table headers are in the same order as Ref table 2 (as per your example) then try this formula in Res!B2
=SUM(SUMIF(Ref1!$B$1:$E$1,IF(Ref2!$A$2:$A$6=Res!$A2,Ref2!B$2:B$6),INDEX(Ref1!$B$2:$E$4,MATCH(Res!$A2,Ref1!$A$2:$A$4,0),0)))
confirm with CTRL+SHIFT+ENTER and copy down and across
That gives me the same results as you get in your results table
If the months might be in different orders then you can add something to check that too - I assumed that the types in results table row labels might be in a different order to Ref table 1, but if they are always in the same order too (as per your example) then the INDEX/MATCH part at the end can be simplified to a single range

Resources