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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
webportal
Impactful Individual
Impactful Individual

Parameterized report with native SQL queries

Hi,

 

I'm retrieving data from SQL server with a query like:

 

SELECT * FROM MY_TABLE
WHERE D_ReferenceDate >= 202312

Is there a way to let the Power BI user choose which reference date from which retrieve the data from?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @webportal 

 

This can be possible with the help of Dynamic M query parameters in Power BI Desktop. This feature can let you bind a column field to a query parameter which is used in the M query. The column field can be used in a slicer in the report for report users to switch different values. The M code will then be modified by the slicer selections to send different queries to the data source. 

 

As the dynamic queries will be affected by the slicer selections, the underlying table must be in DirectQuery mode. There are some considerations and limitations you need to be aware of, please read Considerations and limitations section from the linked documentation above. 

 

Hope this would be helpful. 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

 

View solution in original post

4 REPLIES 4
webportal
Impactful Individual
Impactful Individual

@dufoq3 

Thanks for your help.

I was thinking about having the Power BI user defining the cutoff date (not Power Query parameters).

Anonymous
Not applicable

Hi @webportal 

 

This can be possible with the help of Dynamic M query parameters in Power BI Desktop. This feature can let you bind a column field to a query parameter which is used in the M query. The column field can be used in a slicer in the report for report users to switch different values. The M code will then be modified by the slicer selections to send different queries to the data source. 

 

As the dynamic queries will be affected by the slicer selections, the underlying table must be in DirectQuery mode. There are some considerations and limitations you need to be aware of, please read Considerations and limitations section from the linked documentation above. 

 

Hope this would be helpful. 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

 

dufoq3
Community Champion
Community Champion

Power Bi Desktop user can edit parameters, but not a user of published report - maybe there is a way, but not in my knowledge 😉


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

dufoq3
Community Champion
Community Champion

Hi, it is possible. Create new parameter.

 

dufoq3_0-1715606282089.png

 

Edit your Source step:

= Odbc.Query("dsn=Your_SQL_Connection", "SELECT * FROM MY_TABLE WHERE D_ReferenceDate >= '" & DateParameter & "'")

 

Now you can select your parameter in query panel (left) and enter valid value i.e. 202312 etc.

 

This is how it works with my data:

dufoq3_1-1715606521662.png

 


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
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.