Related
I have sales data that gives me dates in a bad format. Every new sale gets automatically added to the sheet. Looks like this:
Column A
Column B
Column C
Order 1
2022-12-02T02:09:37Z
$1025.19
Order 2
2022-12-02T01:25:15Z
$873.65
This will continue on for all sales. Now the date format is UTC for whatever reason and I can't adjust that, so within this formula I have to subtract 6 hours to get it to central time. I'm trying to create an auto-updating chart that shows an average day for 7 days, so I'm trying to do a sumif formula.
Here's what I have on Sheet2:
=sumif(Sheet1!C:C,index(split((index(split(Sheet1!B:B,"T"),1)+index(split(left(Sheet1!B:B,19),"T"),2))-0.25,"."),1),A1)
Where A1 is a single date. Testing this with one date and not the range shows that it does match. When I do the range, the total comes to 0, even though multiple different dates should match. What am I doing wrong?
Assume A1 has the value: 2022-12-02T02:09:37Z
Apply this formula:
=LAMBDA(RAW,TUNEHOUR,
LAMBDA(DATE,TIME,
TEXT((DATE&" "&TIME)+TUNEHOUR/24,"yyyy-mm-dd hh:mm:ss")
)(TEXT(INDEX(RAW,,1),"yyyy-mm-dd"),REGEXREPLACE(INDEX(RAW,,2),"Z",""))
)(SPLIT(A1,"T"),-6)
returns:
2022-12-01 20:09:37
And assume you have a set of data like this:
you can apply this formula:
=ArrayFormula(
LAMBDA(DATES,AMOUNTS,START,END,DFORMAT,TFORMAT,SKIPBLANK,TUNEHOUR,
LAMBDA(DATES,AMOUNTS,DTFORMAT,START,END,
LAMBDA(DATES,TIMES,
LAMBDA(VALIDDATES,AMOUNTS,
TEXT(SUM(FILTER(AMOUNTS,VALIDDATES>=START,VALIDDATES<=END)),"$#,##0.00")
)(TEXT((DATES&" "&TIMES)+TUNEHOUR/24,DTFORMAT),IF(ISNUMBER(AMOUNTS),AMOUNTS,VALUE(REGEXEXTRACT(AMOUNTS,"^\$(.+)"))))
)(TEXT(INDEX(DATES,,1),DFORMAT),REGEXREPLACE(INDEX(DATES,,2),"Z",""))
)(SPLIT(QUERY({DATES},SKIPBLANK),"T"),QUERY({AMOUNTS},SKIPBLANK),DFORMAT&" "&TFORMAT,TEXT(START,DFORMAT)&" 00:00:00",TEXT(END,DFORMAT)&" 23:59:59")
)($B$5:$B,$C$5:$C,$B$1,$B$2,"yyyy-mm-dd","hh:mm:ss","WHERE Col1 IS NOT NULL",-6)
)
Where you enter a start date and an end date at B1 & B2 to sum up the amount with.
The provided date column will be deducted by 6 hours.
What this formula does is...
format the date column into a valid date,
compare dates from step 1 with a given start and end date as filter condition,
filter the given amount column with conditions from step 2,
sum the result of filter from step 3 as an array,
format the output as price.
Use regexreplace() and query(), like this:
=arrayformula(
query(
{
weeknum(
regexreplace(B2:B, "([-\d]+)T(\d\d:\d\d).+", "$1 $2")
-
"6:00"
),
C2:C
},
"select Col1, avg(Col2)
where Col1 is not null
group by Col1
label Col1 'week #' ",
0
)
)
I think you're trying to split the values and sum them. I can't understand fully what's the purpose of 19 in LEFT function, and why are you again splitting it? Maybe some approach similar to yours is use LEFT function with 10 characters for the date, and MID from 12th character to get the time. Then substract .25 for the 6 hours as you did, and ROUNDDOWN with 0 digits to get the only the day
=ARRAYFORMULA(ROUNDDOWN(LEFT('Sheet1'!B:B,10)+MID('Sheet1'!B:B,12,8)-0.25,0))
And then you can insert it in your SUMIF:
=SUMIF(Sheet1!C:C,ARRAYFORMULA(ROUNDDOWN(LEFT(Sheet1!B:B,10)+MID(Sheet1!B:B,12,8)-0.25,0)),A1)
I have a problem getting the right "Price" for a product based on Effectivity date. I've checked on StackOverFlow but on Google Sheet is not mentioned
I need a table of Effective Price table after querying Price change history table
Please help me solve this problem
Thanks
Try for chosen codes
=query(A:C,"select B,C where A='"&E3&"' and C<=DATE'"&TEXT($E$1,"yyyy-MM-dd")&"' order by C desc limit 1",0)
other solution, by one formula for all codes at once
=arrayformula(iferror(vlookup(unique(A2:A),query(A2:C,"select A,B,C where C<=DATE'"&TEXT($E$1,"yyyy-MM-dd")&"' order by C desc ",0),{1,2,3},0)))
for all codes at once, including those that are out of bounds
=sort(arrayformula(iferror(vlookup(unique(A2:A),
{query(A2:C,"select A,B,C where C<=DATE'"&TEXT($D$1,"yyyy-MM-dd")&"' order by C desc ",0);
query(A2:C,"select A,' ','-' where A is not null ",0)},
{1,2,3},0))))
Formula in E3
=QUERY(A:C,"select A,max(C) where C <= date '"&TEXT(E1,"yyyy-MM-dd")&"' and A is not null group by A label A '',max(C) ''",1)
Formula in G3
=ArrayFormula(VLOOKUP(E3:E&F3:F,{A:A&C:C,B:B},2,FALSE))
If you want to have the same sequence of columns as yours, you need 3 formulas.
Given two tables like those above. The first one contains the data that should be filtered as a single string in the second one.
1st table
A
B
C
D
E
...
M
1st row
Tese
1
Tema
3
Vinculo
...
221
2nd row
Tese
2
Tema
5
Sem
...
443
3rd row
Tese
5
Tema
9
Vínculo
...
221
4th row
Tese
7
Vinculo
...
221
2nd table
A
B
1st row
221
Tese 1>Tema 3>Vínculo>Tese 5>Tema 9>Vinculo>Tese 7>Vinculo
2nd row
443
Tese 2>Tema 5>Sem
Also, as the table is huge, I need an array formula or a query...
Is there hope for me?
Link to the actual table here
It's technically possible to do it all in one Arrayformula, but I would not recommend it and do not have the ability to answer follow up questions. See this sample sheet.
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(TRIM(QUERY(MID(QUERY(SPLIT(FLATTEN("00000_"&Data!M2:M&"#|"&TEXT(ROW(Data!A2:A)*10+{1,2,3},"00000")&"_>"&{Data!A2:A&" "&Data!B2:B,Data!C2:C&" "&Data!D2:D,Data!E2:E}),"|",0,0),"select MAX(Col2) where not Col2 ends with ' ' group by Col2 pivot Col1"),7,1000),,9^9))),"# >",0),"offset 1",0))
You need multiple query statements for each unique value in column M:
So in the first column (assuming this is a different sheet) use:
=UNIQUE(Sheet1!M1:M)
Then on the second column use:
=TEXTJOIN(">",TRUE,TRANSPOSE(FLATTEN(QUERY(Sheet1!$A$1:$M,"select A,B,C,D,E where M = "&$A1))))
Since ARRAYFORMULA does not support multiple query statements on different conditions, you need to drag down or use autofill.
Sample:
I have 2 sparklines. Both are created based on historical share prices of stocks from a year ago to today.
I want to create a new sparkline that is the sum of these 2 charts. Is this possible given that the have the same number of data points i.e 365.
e.g
=SPARKLINE(GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),{"charttype","line";"linewidth",1;"color","#5f88cc"})
=SPARKLINE(GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily"),{"charttype","line";"linewidth",1;"color","#5f88cc"})
You can join them as a single array and then use query to add them:
=SPARKLINE(
QUERY(
{
GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),
GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily")
},
"select Col1, Col2+Col4",
1
)
)
Rundown
We first join the two arrays. To do so we use the array syntax {A,B} to join them row by row, making a 4 column array:
={
GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),
GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily")
}
Now we can apply a query to get the values we want:
=QUERY(
{
GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),
GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily")
},
"select Col1, Col2+Col4",
1
)
The query is making 2 rows:
The date column. Since it should be the same for both, no need to change anything
The sum of the 2 Close columns (2 and 4)
After that we can simply wrap everything to the SPARKLINE function, and we have our final result.
If you don't like having the whitespace characters, you can remove them without any problem.
Reference
Using arrays in Google Sheets (Google Docs Editors Help)
QUERY function (Google Docs Editors Help)
In Google Sheets, I have a range containing list of events along with how many times they take place each day. I'm displaying this data on another sheet in columns, by querying out each event and giving it a column. The problem I run into is that some dates don't have an occurrence of an event, and this doesn't add a corresponding row with a count of '0' into my source data, breaking how I render my data elsewhere.
Here's an example of the source format (notice that Oct 2nd doesn't have any Event 2 data):
2019-10-01,Event 1,12
2019-10-01,Event 2,8
2019-10-02,Event 1,16
2019-10-03,Event 1,7
2019-10-03,Event 2,21
...and then I run queries like this to populate a column:
=QUERY(event_data, "SELECT C WHERE B = 'Event 1' GROUP BY A)
Now if I do this for Event 2, it will follow up the Oct 3rd number right after Oct 1st, and the gap would make it look like those results were from Oct 2nd when I show these two events side by side:
Date Event 1 Event 2
2019-10-01 12 8
2019-10-02 16 7
2019-10-03 21
Is there any reasonable way to solve this within Google Sheets? I know you can't really do an left/inner joins in a query.
I think the better way to do this is rewrite the SQL query I used to populate the source range, so that it returns a row like this in the first place:
2019-10-02,Event 2,0
Just wondering if there's any way around that.
you can pivot stuff in QUERY:
=QUERY(A1:C, "select A,sum(C) where A is not null group by A pivot B", 0)