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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
cdellapietra
New Member

Dynamic M Query Using Related Field

Hi Folks,

 

I have the following table in Power BI where 'Codes' is bound to a parameter named 'SelectedCodes':

cdellapietra_0-1738945221905.png

'SelectedCodes' is used in my DirectQuery to Oracle using string interpolation in there WHERE clause to filter results. This all works fine when I have a slicer on 'Codes', but I'd like to present users with a slicer on 'Category' instead. Switching my slicer from 'Codes' to 'Category' seems to break the Dynamic M query, causing my 'SelectedCodes' parameter to always resort to its default.

 

Is there a way to achieve a functioning dynamic query when filtering on 'Category'?

 

6 REPLIES 6
v-kpoloju-msft
Community Support
Community Support

Hi @cdellapietra,

Thanks for reaching out to the Microsoft fabric community forum.

 

After reviewing the details you provided, here is a few workarounds that might help resolve the issue. Please follow the steps below:

I would also take a moment to personally thank @Akash_Varuna, for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.

 

  • Please ensure that dynamic M query parameters are enabled in Power BI Desktop. This feature allows report viewers to configure filter or slicer values for an M query parameter.
  • To do this, open Power BI Desktop and navigate to Home > Transform data > Transform data to access the Power Query Editor. In the ribbon, select New Parameters under Manage Parameters. Complete the parameter details and reference it in the M query using the Advanced Editor.

  • Utilizing dynamic M query parameters can optimize query performance by incorporating filter selections into source queries at the appropriate point.

Please go through the following link for more information about dynamic parameters:
Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn

 

If this post helps, then please give us 'Kudos' and consider Accept it as a solution to help the other members find it more quickly.

 

Best Regards.

Hi @cdellapietra,

 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you.

Hi @cdellapietra,

 

We have not yet received a response regarding our previous reply and would like to check if your issue has been resolved. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

 

Thank you.

Hi @v-kpoloju-msft 

Apologies, I was away from the office recently. I'm sorry to report neither of the proposed solutions in this thread worked for me. Thank you for your suggestions.

 

Hi @cdellapietra,


Thank you for providing the update on the issue. If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

 

Best Regards.

Akash_Varuna
Solution Sage
Solution Sage

Hi @cdellapietra , Could You please try these 

Ensure Relationship: Confirm there's a relationship between "Category" and "Codes" in your data model.
Create a Calculated Table: Use DAX to capture "Codes" filtered by the selected "Category":
     SelectedCodes = DISTINCT(FILTER('YourTable', 'YourTable'[Category] IN VALUES('CategoryTable'[Category])))
Modify Parameter: Update the SelectedCode parameter in Power Query to dynamically use filtered "Codes":
     SelectedCodes = Table.ToList(SelectedCodes, Combiner.CombineTextByDelimiter(","))
Update Query: Pass the dynamic parameter in your SQL WHERE clause:

     SELECT * FROM YourTable
     WHERE Code IN (#"SelectedCodes")
     If this post helped please do give a kudos and accept this as a solution 
     Thanks In Advance

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors