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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

how to pass managed params through a query and then filter by these parameters

How can i pass managed parameters througth a query.

 

I have created 2 managed parameters i want to filter by these variables 

 

muhammadpathan_0-1711536395890.png

 

I have a record date table

 

muhammadpathan_1-1711536562545.png

how do i add these parameters in query and filter by RecordDate. i want all 

the records between start date and up to an including end date using the parameter values i have defined

 

I have the following so far

 

let
// Define a function that takes Id and EventName as parameters
DynamicQuery = (Id as number, EventName as text) =>
let
// Construct the SQL query string dynamically using the function parameters and include filtering for RecordDate
QueryString = "SELECT TOP (10000) [RecordTime],[RecordDate], [Value], [VariableName] FROM [dbs].[myv] WHERE Id=" & Text.From(Id) & " AND EventName='" & EventName & "' ORDER BY RecordTime DESC",
// Connect to the database with the dynamic query string
Source = Sql.Database("myserver", "nydb", [CommandTimeout=#duration(0, 0, 1, 0), Query=QueryString]),
// Group rows by RecordTime
#"Grouped Rows" = Table.Group(Source, {"RecordTime"}, {{"AllData", each _, type table [RecordTime=datetime, RecordDate=date, Value=nullable text, VariableName=nullable text]}}),
// Expand AllData to include RecordDate along with Value and VariableName
#"Expanded AllData" = Table.ExpandTableColumn(#"Grouped Rows", "AllData", {"RecordDate", "Value", "VariableName"}, {"RecordDate", "Value", "VariableName"}),
// Change the type of Value to number
#"Changed Type" = Table.TransformColumnTypes(#"Expanded AllData",{{"Value", type number}}),
// Pivot the table based on VariableName
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[VariableName]), "VariableName", "Value", List.First)
in
#"Pivoted Column",
// Invoke the function with sample parameters
Result = DynamicQuery(71, "myevent")
in
Result

 

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

You can check this video,but be careful - you've created DATE parameter when your column is DATETIME!


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

1 REPLY 1
dufoq3
Super User
Super User

You can check this video,but be careful - you've created DATE parameter when your column is DATETIME!


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.