Forum Discussion
power query | parameter query to filter data a predefined list from google bigquery database
hi,
i get my data for period beginning 01 January 2015 from google bigquery as follows:
Source = Value.NativeQuery(GoogleBigQuery.Database()
{[Name="abc-stock"]}[Data],
"select * from abc-stock.uk.uk
where (ORIGIN='LAX' or DEST='LAX')",
null,
[EnableFolding=true])
i'd like to create a parameter query to filter the ORIGIN and DEST from a pre-defined list when getting the data from google bigquery.
i'd appreciate any help to show me how to parameter query for that.
tks & krgds, -nik
5 Replies
- ChielFaberSuper User
I think you can solve this in the following way.
When you have a datasource that provides the input you can load this table in Powerquery. Manipulate the data so that you only get one column with the desired filter values.
When you don't have a datasource and you need to input the values yourself you can create a table:
letm_table= #table(type table[#"input"=text],{{"LAX"},{"Second value"},{"Third value"}})inm_tableEither option would need to give you a one column table with the distinct values that you want to input in the where clause.The next step is to convert the table to a list with the following function Table.ToList:#"Converted to list" = #"Name previous step"[column name],When you converted the table to a list you van use the Text.Combine formula to prepare the list as an input value for your where parameter
Inputvalue = Text.Combine( #"Converted to list",",") the ", is the seperator between the values. You might need to add one more step to add a " before the first value.The result is a one column list which you can use as input for the where clausule. The native query would need to be adjusted like this:"select * from abc-stock.uk.uk
where (ORIGIN in (" & InputlistOrigin &" ) or DEST in ("& InputlistDEST &" ))"Hope this is helpfull.- hood2mediaResolver II
- OlivierlnFrequent Visitor
Does it work? 🙂
- OlivierlnFrequent Visitor
Dear all,
It finaly worked !The Parameter needs to be declared as “&ParameterName&”
If this is in a where clause set as below xxxx where ‘“&ParameterName&”’
Source = Value.NativeQuery(
GoogleBigQuery.Database([BillingProject = BQ_Source]){[Name = BQ_Source]}[Data],
"SELECT
*
FROM dwh.Table AS sa
where 1=1
and sa.Country= '"&CountrySelection&"'"Then you need a parameter name CountrySelection where you set your string
,
null,
[EnableFolding = true]
)thank you for your help