Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
zzzsharepoint
Helper I
Helper I

Pass number of days in the bigquery from parameter

I am using Google Big Query as my connector to Power Bi and have the below query to get my data. In the query if you see I have hard coded the value as 7 to get data for last 7 days. I would like to make this more dynamic and get my result for 3 days someday it can be 10 day etc. How can I do this? Can someone show me with steps to be done here

 

 

SELECT
  project.id AS project_id,  
  (
           SELECT value
           FROM   UNNEST(labels)
           WHERE  KEY='team') AS team,
  (
           SELECT value
           FROM   UNNEST(labels)
           WHERE  KEY='service') AS service,  
    SUM(cost) AS cost
FROM `XXXX_jjjSSS_1234`
WHERE DATE(export_time) > DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY)
GROUP BY
  project_id, team, service
ORDER BY cost DESC
4 REPLIES 4
Anonymous
Not applicable

Hey @zzzsharepoint ,
In the query text, you can pass the powerQuery parameter. something like below: 
For ex., If parameter name is _paramIntervalDays then query looks something like : 

"SELECT
  project.id AS project_id,  
  (
           SELECT value
           FROM   UNNEST(labels)
           WHERE  KEY='team') AS team,
  (
           SELECT value
           FROM   UNNEST(labels)
           WHERE  KEY='service') AS service,  
    SUM(cost) AS cost
FROM `XXXX_jjjSSS_1234`
WHERE DATE(export_time) > DATE_SUB(CURRENT_DATE(), INTERVAL" & _paramIntervalDays & " DAY)
GROUP BY
  project_id, team, service
ORDER BY cost DESC"

Get error as DataSource.Error: ODBC: ERROR [42000] [Microsoft][BigQuery] (70) Invalid query: Could not cast literal "& LastDays &" to type INT64 at [23:61]
Details:
DataSourceKind=GoogleBigQuery
DataSourcePath=GoogleBigQuery
OdbcErrors=[Table

 

Here is the query I tried:

 

SELECT
  project.id AS project_id,  
  (
           SELECT value
           FROM   UNNEST(labels)
           WHERE  KEY='team') AS team,
  (
           SELECT value
           FROM   UNNEST(labels)
           WHERE  KEY='service') AS service,  
    SUM(cost) AS cost
FROM `XXXX_jjjSSS_1234`
WHERE DATE(export_time) > DATE_SUB(CURRENT_DATE(), INTERVAL" & LastDays & " DAY)
GROUP BY
  project_id, team, service
ORDER BY cost DESC
 
Any Idea what is wrong "LastDays" is my paremeter of text type
Anonymous
Not applicable

looks like It is a syntax error, you can try writing your as a text and pass the 'querytext' as a query parameter in your connection

 

Rushki_0-1668694558972.png

 

The query formed looks something like: 

Rushki_1-1668694746076.png

 

Its not working.. have you tried it with Big Query? I created a Parameter of type TEXT and gave a default value of 7. and now I am passing the paremeter as suggested by you in my big query but always end up in error as mentioned above.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors