Google Sheets QUERY(): Add Additional Blank Rows - sql

I'm studying how Major Events affect the US and AU stock markets, such as the Dotcom bubble, 911, COVID etc.
Using GoogleFinance(), I'm trying to compare the weekly close for the S&P500 Index (INDEXSP:.INX) and the ASX All Ords Index (INDEXASX:XAO) for various time periods, for example 2000-2010.
However, the ASX All Ords only returns records from 2010-04-20, which is a problem as I'd like to display the data as a Chart.
The following is one of the functions that return the data:
=QUERY( googlefinance(E10,"all",$F7,$F8,"WEEKLY"), "SELECT Col1, Col5 LABEL Col1 'All Ords', Col5 'Value' ")
I'd like to add extra blank rows for the ASX data so the weekly dates line up. In the case of the range 2000-2010, I need to add 67 blank rows to align dates.
Is there any way to structure the Query, such as adding a UNION clause somehow, to achieve this? Or any alternate method?

You'll want to use a vlookup function of the dates on the S&P results INTO the array of the ASX results.
I've laid out the basics here on this spreadsheet that was created specifically for this thread.
the formula I'm talking about is in cell D4 on the tab called Comparison. I rounded the dates so that the chart is cleaner.
=ARRAYFORMULA(IFERROR(VLOOKUP(B4:B,QUERY(ROUND(GOOGLEFINANCE(D3,"close","1/1/1990",TODAY(),"weekly"),{0,2}),"offset 1",0),2,TRUE)))

Related

Excel 2016: Conditional Formatting: Highlight row if cell value is in list

Excel 2016 Conditional Formatting question:
I have two tabs, Data and List:
Data has 5 columns. Column A is the item ID number, the others have
project related data.
List has 1 column. This is a list of ID numbers
that have been processed.
Here is the question:
How do I highlight the rows for processed ID numbers? I want to be able to add ID numbers to List as I process more rows. I want to see processed items in Data in green highlight, because green makes the boss happy!
Looking forward to your input!
I would use a VLOOKUP to find the value in the List sheet. An error means the value doesn't exist. Since you want to know if it does exist, just invert the boolean result with NOT
=NOT(ISERROR(VLOOKUP($A1,List!$A:$A,1,FALSE)))
Note: This is a Classic > Formula formatting rule, and the lookup value is $A1 because my "applies to" range starts on row 1 (and we always look at col A).
Rule:
Formatting Range:
Result:

Sorting a range of values correctly in vba

I have the following data in a pivot table. To the left, is described a range and to the right the number of cells within that range. I would like to learn a code that correctly arranges the range in the left and color codes anything after "80-89". I have used the sort function but it doesn't seem to work. Please help.
Days Count of PR ID
"10-19" 656
"0-9" 480
"20-29" 190
"30-39" 115
"40-49" 65
"50-59" 47
"70-79" 28
"60-69" 23
"80-89" 12
"110-119" 3
"120-129" 2
"130-139" 1
"100-109" 1
"180-189" 1
Use a helper column which can then be used for the numerical sort. So in the source data add a helper column next to the days column that goes 1,2,3,4 etc ranking days - you can use a vlookup to pull in the right rank for each days group. Then use this to sort on in your pivottable. Conditional formatting can then do your colouring as well based on the helper column value.
Data with helper column and vlookup table:
Note that this would be your actual backing data before aggregating up that would have the helper column.
Pivot using helper column to order (note: you would use Count not Sum):
Conditional formatting:
Add a conditional formatting rule (to meet your requirements) using the helper column value:
Result:

Transpose Columns in Order using Excel VBA

I have an extremely large amount of data needs to be transposed in order using the example on the image below. The left side of the image is how the information comes from the report, and the right side is what I need it to look like.
I have tried to use the Transpose paste special but it results in 3000+ columns of information. I have also tried pivot tables but I get the information out of order.
The three pieces of "Info" are per employee. As it stands now, the lines are vertically but in our end result we should have three rows per employee.
Transpose Left Original Data Right Outcome Needed
you can achieve this by the below formula
F1 = INDEX($A$1:$A$3,1+QUOTIENT(ROW()-ROW($F$1),3))
G1 = VLOOKUP(F1,$A$1:$D$3,2+MOD(ROW()-ROW($F$1),3),FALSE)
So if you have 3000 lines of data, the formula should be dragged to 9000 rows.

Index and Match Excel

I'm creating a vacation tracker in Excel. The first sheet pulls the data from SharePoint which has Start Date, End Date and a Date Difference calculation.
Sheet1
A2=12/16/2015
B2=12/20/2015
C2=5
The second sheet is the visualization of the data. It starts with cell B1 and goes out for 90 days. Is is a word representation of the date. Here is the formula I'm using =UPPER(TEXT(B2,"DDD"))
Sheet2
B1=WED
C1=THU
D1=FRI
E1=SAT
F1=SUN
The next row always B2 has a formula which is always today's date. From there I add one date to increment the dates out to 90 days. B2=Today() and the other cells =B2+1 and so forth
B2=16
C2=17
D2=18
E2=19
F2=20
The problem I'm running to is that our boss can have 3 calendar entries consisting of different dates. So when I perform a SharePoint pull I have 3 different rows of vacation dates. I'm experimenting with an Index and Match example, however the data match it is placed in a new row. How do I place the data on the same row?
I'm not convinced this has much to do with VBA. Seems enough detail of final design but rather light on the data gathering process. However when I perform a SharePoint pull I have 3 different rows of vacation dates hints at a use for Subtotal. Three rows may be 'converted' into one:
where the unshaded part (some cells with Xs) is assumed to be a representation of the current SharePoint data extract. Subtotal is able to add the rows shown lightly filled, which might then be used to =VLOOKUP("Boss"&" Count",A:F,n,0) where n represent the choice of column label.

Dynamic reference in excel formula

I have the following array formula which works for what I want to do but I'm trying to change the formula when a user selects a value.
=INDEX($A$2:$B$70,SMALL(IF($A$2:$B$70=$A$121,ROW($A$2:$B$70)),ROW(1:1))-1,1)
It's used for a monthly report and the user will choose from a drop down the day of the month, e.g 1,2,3 - 31.
So if the user selects 1 from the drop down menu I want the formula to use the above formula.
If they select 2 for example I want the formula to move over a column so it would change to
=INDEX($A$2:$C$70,SMALL(IF($A$2:$C$70=$A$121,ROW($A$2:$C$70)),ROW(1:1))-1,1)
and so on moving over a column at a time.
It this possible at all or can it even be done without VBA?
I have an example of what I want done on the following link
https://docs.google.com/spreadsheets/d/1MDOzoQxYLgW-UOyljZsMwSu8zyAB7O2k1V-bTNP5_F0/edit?usp=sharing
All the data is on the first tab called staff. Each employee has a row and the duty assigned under the corresponding day column.
On the Roster tab it summarises each day. So what I am trying to get to happen is when you choose the day of the month (or preferably the actual date) the sheet changes to reflect the data.
At the moment the code I have working does for just Day 1 because the column references are coded into the formula. I was hoping to somehow choose 6 for example from the drop down and then the formula will map chosen day to the corresponding range in the raw data and update the formula and change the formula from Staff!$A$2:$B$68 to Staff!$A$2:$G$68.
If the formula finds no more entries if shows #NUM! but I intended to use the function ISERROR() to replace #NUM! with "".
This is what I'm trying to achieve it if makes sense?
There are a few issues here/ You are returning the value from column A so the first range can be $A$2:$A$70 and that means you don't need the 1 to specify the column_num. The IF statement was covering A2:C70 when you really only want either B2:70 or C2:C70 depending on the 1 or 2.
Assuming that A122 has either a 1 or 2 in it then,
=INDEX($A$2:$A$70, SMALL(IF(INDEX($B$2:$C$70, 0, $A$122) = $A$121, ROW($1:$69)), ROW(1:1)))
Standard non-array alternative,
=INDEX($A$2:$A$70, SMALL(INDEX(ROW($1:$69)+(INDEX($B$2:$C$70, 0, $A$122) <> $A$121)*1E+99,, ), ROW(1:1)))