Forum Discussion

tmendoza's avatar
tmendoza
Resolver I
9 months ago
Solved

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
    source
  • tmendoza For everyone, it is fixed, and the solution was to remove "&" from the table name "P&L_GLDQ" 🤷

24 Replies

    • tmendoza's avatar
      tmendoza
      Resolver I

      Thank you for your response!

      I can confirm that the period column is of type, 'Whole number'. (See below)

       

       

  • 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.

  • v-prasare's avatar
    v-prasare
    Community 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 response

     

     

     

    Thank you for your patience and look forward to hearing from you.
    Best Regards,
    Prashanth Are
    MS Fabric community support

    • tmendoza's avatar
      tmendoza
      Resolver I

      Hey there, I thought I replied to everyone.

      No, the community member answer did not resolve my issue.

  • 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
          Source

     

    After 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.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    • tmendoza's avatar
      tmendoza
      Resolver 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?

       

  • tmendoza, there is no setting as such. I'm wondering if you run the query in the backend using SSMS or other tool with the same slicer value, does it work? I'm wondering if there is some issue at the source that the query is not returning the data. 

    • tmendoza's avatar
      tmendoza
      Resolver 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
  • tmendoza very hard to tell what is going on here. Maybe easier is to connect for screen sharing and see if something else is going on. 

  • tmendoza, send me a private message with the link to connect. I will check the message and join. I would prefer Teams and Zoom. 

    • tmendoza's avatar
      tmendoza
      Resolver I

      Sounds good. I'm going to ask for approval and I will get right back at you.

  • tmendoza For everyone, it is fixed, and the solution was to remove "&" from the table name "P&L_GLDQ" 🤷