If I have a table like below:
ID A B C D(ate)
ASDF 1 2 1 12/12/2016
ASEF 1 2 3 12/13/2016
AFDS 2 3 1 12/13/2016
ASFA 2 3 4 12/14/2016
And I want to get the latest based on a pair (A, B) and the latest date (D), how would I set up a table to work well with this request, and what kind of query would I use to retrieve that?
The output would give me values for the IDs ASEF and ASFA.
I'm using the aws-go-sdk to run this, but I should be able to convert any solution to that SDK.
You should use attribute A as HashKey(PartitionKey) and Date as RangeKey(SortKey). With partitionKey only equality condition(==) can be used. RangeKey supports <,>,=,Between operations.
Check this link
Related
I have a table like this:
a
b
c
1
2
abc
2
3
4.00
note c2 is text while c3 is a number.
When I do
=QUERY(A1:C,"select *")
The result is like
a
b
c
1
2
2
3
4.00
The "text" in C2 has been missed. You can see the live sheet here:
https://docs.google.com/spreadsheets/d/1UOiP1JILUwgyYUsmy5RzQrpGj7opvPEXE46B3xfvHoQ/edit?usp=sharing
How to deal with this issue?
QUERY is very useful, but it has a main limitation: only can handle one kind of data per column. The other data is left as blank. There are usually ways to try to overcome this from inside the QUERY, but I've found them unfruitful. What you can do is just to use:
={A:C}
You can work with filters by its own, but as a step-by-step to adapt the main features of query: If you need to add conditions, use LAMBDA INDEX and FILTER
For example, to check where A is not null:
=LAMBDA(quer,FILTER(quer,INDEX(quer,,1)<>""))({A:C}) --> with INDEX(quer,,1), I've accesed the first column
Where B is more than one cell and less than other:
=LAMBDA(quer,FILTER(quer,INDEX(quer,,2)>D1,INDEX(quer,,2)<D2))({A:C})
For sorting and limiting an amount of items, use SORTN. For example, you want to sort by 3rd column and limit to 5 higher values in that column:
=LAMBDA(quer,SORTN(FILTER(quer,INDEX(quer,,1)<>""),5,1,3,0))({A:C})
Or, to limit to 5 elements without sorting use ARRAY_CONSTRAIN:
=ARRAY_CONSTRAIN(LAMBDA(quer,FILTER(quer,INDEX(quer,,1)<>""))({A:C}),5)
There are other options, you can use REGEXMATCH and other options, and emulate QUERYs functions without missing data. Let me know!
shenkwen,
If you are comfortable with adding an Google App Script in your sheet to give you a custom function, I have a QUERY replacement function that supports all standard SQL SELECT syntax. I don't analyze the column data to try and force to one type based on which is the most common data in the column - so this is not an issue.
The custom function code - is one file and is at:
https://github.com/demmings/gsSQL/tree/main/dist
After you save, you have a new function from your sheet. In your example, the syntax would be
=gsSQL("select a,b,c from testTable", {{"testTable", "F150:H152", 60, true}})
If your data is on a separate tab called 'testTable'(or whatever you want), the second parameter is not required.
I have typed in your example data into my test sheet (see line 150)
https://docs.google.com/spreadsheets/d/1Zmyk7a7u0xvICrxen-c0CdpssrLTkHwYx6XL00Tb1ws/edit?usp=sharing
I'm trying to use Vlookup in a Google Sheet using an ID to match 2 separate tables. If there is no match in the first table, then I am telling the code to search for it in the second table. The lookup value, and 2 tables are all in different sheets and it doesnt work but I am able to get another test to work when they are all on the same sheet so I am not sure why that is.
For example this works
arrayformula(IFERROR(if(vlookup(A2:A,D2:E,2,FALSE)<>"",vlookup(A2:A,D2:E,2,FALSE),vlookup(A2:A,G2:H,2,FALSE))))
ID
Vlookup
ID
Vlookup value
ID
Vlookup value
1
One
1
One
1
2
Two
2
2
Two
3
Three
3
Three
3
4
Four
4
4
Four
5
This Full Formula fails
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE)<>"",vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE),vlookup($B$2:$B,'Sheet2'!$A$1:$N,4,FALSE))))
I'm not sure how to moidfy my formula, which works in individual parts and together it matches data in Sheet1! but not on Sheet 2! based on my tests.
Testing Results
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE) --> Vlookkup matches Sheet1! data also
Arrayformula(vlookup($B$2:$B,'Sheet2'!$A$1:$N,4,FALSE) -->matches Sheet2! data
Modify the second part of the data to "False"
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE)<>"",vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE),"False"))))
Result: Anything that does not match in either Sheet 1 or Sheet 2 says "False". But a match in Sheet 1 works and a match in Sheet 2 shows blank.
Modifying the IF statements to make consistent did not work either
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE)<>"",vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE),
IF(vlookup($B$2:$B,Sheet2!$A$1:$N,4,FALSE)<>"",vlookup($B$2:$B,Sheet2!$A$1:$N,4,FALSE),""))))
How can I modify the formula so that it works in unison?
This works
=arrayformula(IFERROR(if(vlookup(A2:A,Sheet1!A1:B5,2,FALSE)<>"",vlookup(A2:A,Sheet1!A1:B5,2,FALSE),vlookup(A2:A,Sheet2!A1:B5,2,FALSE))))
Still unsure if there is another error in the formula above that didn't work as I think it should have worked
i have a dataset like this
Order
id
expected date
1
11-04-2022
2
10-04-2022
2
14-04-2022
Order Event
Id
Order Id
Order status
Date
1
1
created
01-04-2022
2
1
completed
12-04-2022
3
2
created
01-04-2022
4
2
in progress
07-04-2022
5
2
completed
10-04-2022
6
3
created
10-04-2022
and i need to create a graph that show, for all order with completed status the difference between expected date and actual order date.
How can i archueve that
First, you have to join both of the tables into one because QuickSight can only work with multiple data files if they are merged. You can apply an inner join on the order ID.
Then, you can calculate the difference between the expected date and the order date and add an if-statement to filter out the orders who are not completed yet. You do this by adding a calculated field to your dataset with the following code:
ifelse(
{Order_status}="completed",
dateDiff({expected_date},{Date},"DD"),
0
)
You can also modify this field. Here, I wrote "DD" for the date difference in days, you can also select hours etc.. Also, if the order is not completed, I selected 0 as a default value. To find out more about the commands used in this calculated field, visit this AWS Docs links:
If-Else Command
Date-Diff Command
Now that the calculated field is created, you can plot it together with the order ID.
BR mylosf
Good day,
I have seen from here a solution to control duplicate entries into a single column. A Data validation with this custom formula works well for one column.
I would like to achieve the same effect over multiple columns ... i.e. unique row entries across multiple columns. Take for example below three columns A-C. Only when values {1,2,1} are entered for the second time will the input be rejected.
A B C
1 1 1
1 2 1
1 2 2
2 2 2
1 2 1 X Entry should be rejected.
Is there a quick way to do this using Data Validation - custom formulae?
use custom formula for data validation:
=INDEX(COUNTIF($A$1:$A&"×"&$B$1:$B&"×"&$C$1:$C, $A1&"×"&$B1&"×"&$C1)<2)
I am new to informatica power center tool and performing some assignment.
I have input data in a flat file.
data.csv contains
A,2
B,3
C,2
D,1
And Required output will be
output.csv should be like
A
A
B
B
B
C
C
D
Means I need to create output rows depending upon value in column. I tried it using java transformation and I got the result.
Is there any other way to do it.
Please help.
Java transformation is a very good approach, but if you insist on an alternative implementation, you can use a helper table and a Joiner transformation.
Create a helper table and populate it with appropriate amount of rows (you need to know the maximum value that may appear in the input file).
There is one row with COUNTER=1, two rows with COUNTER=2, three rows with COUNTER=3, etc.
Use a Joiner transformation to join data from the input file and the helper table - since the latter contains multiple rows for a single COUNTER value, the input rows will be multiplied.
COUNTER
-------------
1
2
2
3
3
3
4
4
4
4
(...)
Depending on your RDBMS, you may be able to produce the contents of the helper table using a SQL query in a source qualifier.