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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Passing Parameters to OleDB Datasource

Hello,

 

I am looking to input a date parameter into the OleDB datasource code.

 

=OleDb.DataSource("provider=PIOLEDB.1;data source=osi-pi", [Query="SELECT *#(lf)FROM [piarchive]..[piavg]#(lf)WHERE tag = 'Value1' #(lf)AND timestep = '1h' #(lf)AND time BETWEEN'*-2y'AND'*'"])

 

 

I'd like to add the parameters StartDate and EndDate parameters into the *-2y and * part of the statement, respectively. 

 

Thanks

1 ACCEPTED SOLUTION
rubayatyasmin
Super User
Super User

hi, @Anonymous 

 

first define the start and end date pram then pass it like 

 

let
    StartDate = DateTime.ToText(DateTime.LocalNow() - #duration(730, 0, 0, 0), "yyyy-MM-ddTHH:mm:ss"), // 2 years ago from now
    EndDate = DateTime.ToText(DateTime.LocalNow(), "yyyy-MM-ddTHH:mm:ss"), // Current time
    Source = OleDb.DataSource("provider=PIOLEDB.1;data source=osi-pi", [Query="SELECT * FROM [piarchive]..[piavg] WHERE tag = 'Value1' AND timestep = '1h' AND time BETWEEN '" & StartDate & "' AND '" & EndDate & "'"])
in
    Source

Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

3 REPLIES 3
rubayatyasmin
Super User
Super User

hi, @Anonymous 

 

first define the start and end date pram then pass it like 

 

let
    StartDate = DateTime.ToText(DateTime.LocalNow() - #duration(730, 0, 0, 0), "yyyy-MM-ddTHH:mm:ss"), // 2 years ago from now
    EndDate = DateTime.ToText(DateTime.LocalNow(), "yyyy-MM-ddTHH:mm:ss"), // Current time
    Source = OleDb.DataSource("provider=PIOLEDB.1;data source=osi-pi", [Query="SELECT * FROM [piarchive]..[piavg] WHERE tag = 'Value1' AND timestep = '1h' AND time BETWEEN '" & StartDate & "' AND '" & EndDate & "'"])
in
    Source

Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

Thank you for your response. Is it possible to have the defined variables correspond to the parameters "TrialStart" and "TrialEnd." 

you should be able to do it

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.