Forum Discussion
Dynamic M Query Parameters not working when I make slicer selection
You folks have always been a great help to me.
What am I doing wrong with my Dynamic M Query Parameter set up?
I'm trying to speed up my Direct Query by utilizing Dynamic M Query Parameters.
I followed the directions in the below PBI article:
Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn
I'm using the T-SQL for a single parameter. At the bottom of the page is the code I've inputted into the advanced editor.
As you can see from the code, 'fiscal_period' is the parameter I'm using.
I have an imported table called 'Period' which is related to the Direct Query via 'Period' (see bottom of page).
I've bound the 'Period' column in this table to the 'fiscal_period' parameter.
Things seem to work out up until I actually make a 'Period' selection in the slicer. Making a 'Period' selection in the slicer breaks my visuals and results in the below error message:
"Conversion of an M query in table 'P&L_GLDQ' into a native source query aborted due to too may failures"
I can't find a solution for this.
What am I doing wrong with my Dynamic M Query Parameter set up?
Hoping you folks can give me advice on what I need to do to fix my Dynamic M Query Parameter.
P&L_GLDQ:
let
source = Sql.Database
(
"MCMC.MadeUpServer.com",
"DIY_MadeUpDataBase"
,
[Query = "
Select
*
FROM dbo.vPLGL_ISDashboard
WHERE Period = ('"& Number.ToText(fiscal_period,"D") &"')"])
in
sourcetmendoza For everyone, it is fixed, and the solution was to remove "&" from the table name "P&L_GLDQ" 🤷
24 Replies
- parry2kSuper User
tmendoza looks like your period column is of date type and number.totext is the reason for the error. Can you confirm period is date not number. You probably need to Date.ToText if data type of period column is of type date. Date.ToText - PowerQuery M | Microsoft Learn
- tmendozaResolver I
Thank you for your response!
I can confirm that the period column is of type, 'Whole number'. (See below)
- kushanNaSuper User
Hi tmendoza
What are the requirements for having a relationship between the Periods table and the Direct Query table? Try disabling all the relationships and use the Period column as a slicer to see if it works. I wonder if a continuous loop is running due to the relationships. Also, make sure that the Period column is in the correct format.
- tmendozaResolver I
Prior to the Dynamic M query parameter set up, I built the 'Periods' table to have a '1 to many' relationship with the Direct Query table via 'Period'. It's essentialy a dimention table. Due to this, the Period slicer, which used 'Period' from the 'Periods' table, could filter the direct query via 'Period'.
It was a good thought, but removing the relationship does not seem to solve the issue. The below error message still pops up when I make a slicer selection. When I remove the slicer, the error disapears. It seems to be very sensitive to me using the 'Period' column which is bound to the parameter.
- kushanNaSuper User
oh okay , check if creating a new query source works for you ? https://community.fabric.microsoft.com/t5/Service/Unable-to-convert-an-M-query-in-table-table-name-into-a-native/m-p/1563057#M116483 https://www.reddit.com/r/PowerBI/comments/jo0kdv/unable_to_convert_an_m_query_in_table_xxx_into_a/
- v-prasareCommunity Support
Hi tmendoza,
As we haven't heard back, we would like to confirm if our community members answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.
kushanNa & parry2k ,Thanks for your prompt responseThank you for your patience and look forward to hearing from you.
Best Regards,
Prashanth Are
MS Fabric community support- tmendozaResolver I
Hey there, I thought I replied to everyone.
No, the community member answer did not resolve my issue.
- parry2kSuper User
tmendoza I did a quick demo on my end, and everything is working as expected. Keep everything in context. I'm filtering the customer table on customerID, which is of the number type.
Step1 : Created a parameter called ParamCustomerID:
Step 2: Created a Direct Query Customer table, which will be filtered on the above parameter value:
let Source = Sql.Database("MySQLServer", "MySQLDatabase", [Query="SELECT * FROM Customer WHERE CustomerId = " & Number.ToText(ParamCustomerID)]) in SourceAfter saving the above query, it is filtering the customer table on the ParamCustomerID current value, and in this case, it is value 1
Step 3: Created another table, which is simple IDs and will be used for the slicer, and I called it CustomerSlicer with one column CustomerId:
Step 4: Close and apply (no error at this point)
Step 5: Bind to the parameter,
- go to model tab
- selected CustomerId column in CustomerSlicer table
- under Advanced -> Bind to parameter -> selected ParamCustomerID
Step 6: Added a slicer, and it using CustomerId column from CustomerSlicer table
Step 7: Added a table visual that has two columns from the Customer table, and it is getting filtered as the slicer value is selected.
- tmendozaResolver I
parry2k ,
Thanks for your response.
We have a similar set up, period and customer ID are both numeric.
I followed your steps to the tee and I can see the Power Query editor working and loading the data correctly.
The visual also works when there is no slicer selection.
However, once making a slicer selection with the bound parameter, I'm running into this error message:
Any idea what it could mean?
At this point, I feel like this should have worked by now. Is it possible that there is a dashboard setting that I need to toggle to make the M Query parameter work?
- tmendozaResolver I
Just checked. Backend is working fine. The data is also returned at the power query editor level and report view. The break specificaly happens once a slicer selection is made using the bound parameter. From what I can see, I'm using the right format for it.
let Source = Sql.Database("ABCD.Server.com", "Database", [Query= " SELECT * FROM dbo.vPLGL_ISDashboard WHERE Period = " & Number.ToText(fiscal_period)] ) in Source
- tmendozaResolver I
Sounds good. I'm going to ask for approval and I will get right back at you.