Sheets query using importrange with select where statement referencing sheet cell - select

How do I correctly reference a cell in a sheet such that a query can use the string in the cell as a filter in the query where statement?
The below query fails in the where statement with:
"Error:Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: BADO".
"BADO" is the string in cell C1 referenced in the where statement and is a valid value in Col2 in the importrange sheet.
The query returns all date if "Col2" is entered into cell C1. I've tried several other variations to no avail.
{=QUERY(importrange("1cCQQA3DYwuiSKokzcuqhnUPVV8-Ok2JAZUzG6ryxLf8","$A$2:$F"),
"select * where (Col2="&C1&")")}
Below is my test sheet:
https://docs.google.com/spreadsheets/d/1RY2AXali01-N0fd-zBPPJDO-4vPuoRGsG5dSMn1NBJU/edit?usp=sharing

The formula is right however the mistake is that in where cluase, Col2 requires a string value but we are passing BADO. ideally the synatx needs to be 'BADO' with single quotes. So just added the single quotes in where clause of the formula.
=QUERY(importrange("1cCQQA3DYwuiSKokzcuqhnUPVV8-Ok2JAZUzG6ryxLf8","$A$2:$F"),"select *
where Col2='"&$C$1&"'")
Hope this could help.

Related

Azure Data Factory : returns an array of dates from a specified range

I'm trying to returns an array of dates in data factory. But i just want the user to specify a date range with two parameters, startDate and endDate :
I want to return this array by specifying "12-08-2020" and "12-13-2020" in trigger :
["12-08-2020","12-09-2020","12-10-2020","12-12-2020","12-13-2020"]
Do did not find a simple way to do it yet.
One way i thought about would be :
add a lookup activity on a date dimension,
then add two filters to select only items greater than startDate and lower than endDate.
But this seems to be cumbersome and overkill. Is there a simpler way to do it ?
EDIT :
This answer seems to be relevant (i did not see it at first) : Execute azure data factory foreach activity with start date and end date
I think we can use recursive query in Lookup activity.
The pseudo code is as follows:
In sql we can use this query to get a table:
;with temp as
(
select CONVERT(varchar(100),'12-08-2020', 110) as dt
union all
select CONVERT(varchar(100), DATEADD(day,1,dt), 110) from temp
where datediff(day,CONVERT(varchar(100), DATEADD(day,1,dt), 110),'12-13-2020')>=0
) select * from temp
The result is as follows:
So in ADF, I think we can use a Lookup sql query to return the result what you want.
According to this official document, we only need to replace the parameters of the sql statement.
Next,I will use '#{pipeline().parameters.startDate}' to return a date string, note: There is a pair of single quotes outside.
I set two parameters as follows:
Type the following code into a Lookup activity.
;with temp as
(
select CONVERT(varchar(100),'#{pipeline().parameters.startDate}', 110) as dt
union all
select CONVERT(varchar(100), DATEADD(day,1,dt), 110) from temp
where datediff(day,CONVERT(varchar(100), DATEADD(day,1,dt), 110),'#{pipeline().parameters.endDate}')>=0
) select * from temp
Don't select First row only.
The debug result is as follows:
I had similar use case and ended up using Until with little changes.
Two parameters which takes two parameters start_day and end_day
Also have to introduce two variables for implementing counter logic. more details can be found at how-to-increment-parameter-data-factory
and finally the expression in the untill block is
#less(int(adddays(pipeline().parameters.end_day, 0, 'yyyyMMdd')), int(adddays(pipeline().parameters.start_day, int(variables('counter')), 'yyyyMMdd')))
final note the until block executes when the expression returns false and loops out on true
I managed to get something similar to work with a combination of derived column transformation using a mapLoop() function followed by a flatten transformation.
The derived column expression first calculates an array of dates in a single column.
mapLoop(toInteger((To_Date - From_Date)/86400000)),toDate(addDays(From_Date,#index)))
where 86400000 is the number of miliseconds in 24 hours
The flatten transformation uses this column to unroll the array into separate rows.

Combine fields in transformation from "get rows from result" + info from a query

I have a PDI transformation that gets 3 fields from a result row:
SEARCH_VALUE
Asset
IP_V4_Address
The next hop is a table input that searches based on search value and returns one column value, something like abcd-1234.
SELECT DISTINCT p.txt_reqID FROM ...
Now, after my table input runs, the resulting stream only has 1 column (the txt_reqID). I'd like my output stream to have 4 columns - the original 3 + the new one from the table input. How do I do that?
Here is the transformation and the input row structure:
This is the table input setup:
I'm only able to access the txt_reqID field after the table input, I can't figure out how to tell it to pass the other 3 through.
You can achieve this by having Select values step after the Get rows from result step. Select Values is required to duplicate your SEARCH_VALUE as you need this field in both SELECT and in the WHERE clause and also it can be used to reorder the fields before table input.
In Table input you can use the query like
SELECT DISTINCT p.txt_reqId, ? as SearchValue, ? as Asset, ? as IPV4 address
FROM ... WHERE d.value like ?
Here is the sample for the same
click here for the image

crystal reports multiple function in formula

I am looking to execute 2 Replace functions on the same report field.
When I try
Replace({letter_master.letterBody},'{provider}',{provider.provider_name});
Replace({letter_master.letterBody},'{TotalBalance}',ToText(ToNumber({visit_master.value_7})))
as the formula for the letterBody field, only the second replace is returned.
How can I execute BOTH replace statements on the letterBody field to get both placeholders replaced with real data.
try..
Replace(
Replace({letter_master.letterBody},'{provider}',provider.provider_name})
,'{TotalBalance}',ToText(ToNumber({visit_master.value_7})))

Using 'if' condition in parameters

I am creating JasperReports Server report using iReport. I have a table with 4 columns. The user needs to select through parameter which will be the first column. Depending on what he selects, the other columns be decided.
For e.g. If user selects column 2 in the input control, the column 2 will become the leftmost column and column 1 will take the place of column 2.
What is the best way to do it? Can I use 'if' condition in parameters?
The arrangement of solutions is quite rare. Anyways, you can achieve so by using an expression with a variable.
Simply right-click on the field and click "Edit Expression"
PFirst is a reports parameter
The field expression can be something like
$Pfirst.equals("fieldOne")?fieldOne:"" + $Pfirst.equals("fieldTwo")?fieldTwo:"" + $Pfirst.equals("fieldThree")?fieldThree:""
Add another parameter (uncheck use as a prompt) with your if statement in default value expression.
The whole sql statement can be in this parameter, I assume, but tested with only part of sql statement. In the report query put this new parameters as $P!{paramname}.
Should work.
You can try this:-
If condition for text filed of first column, p_column is a parameter with default value "col1"
$P{p_column}.equals("col1") ? $F{col1} : $F{col2}
If condition for the second text filed of second column:-
$P{p_column}.equals( "col1" ) ? $F{col2} : $F{col1}

ssrs sum function in textbox

I have 2 datasets in my report. And I need to put a number of rows that meet a certain condition in a text box.
Here's what I have so far:
=Sum(IIF((Fields!OPEN_TIME.Value, "calls")=Parameters!Date.Value,1,0))
I get following error while running the report:
The Value expression for the text bix uses an aggregate expression without a scope. A scope is required for all aggregate used outside of a data region unless the report contains exactly one dataset
What do I miss?
Here if you are specifying a dataset name to a field like this "(Fields!OPEN_TIME.Value,"calls")" its a syntax error.. if you are using the field in a table which is assigned to dataset1 and table is assigned to dataset2 or field in a text box, then the field should be used with aggregate or "First", "Last"
Example:
first(Fields!OPEN_TIME.Value, "calls")
last(Fields!OPEN_TIME.Value, "calls")
sum(Fields!OPEN_TIME.Value, "calls")
Count(Fields!OPEN_TIME.Value, "calls") ...etc
In above scenario rather than taking a textbox, take a table with single cell assign the dataset "calls" to it then go for below expression:
=Sum(IIf(Fields!OPEN_TIME.Value = Parameters!Date.Value, 1,0))