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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rnola16
Advocate II
Advocate II

Dynamic M query with arbitrary values

Hi all,

 

I tried to recreate the code from Chris webbs blog. In my case, I'm using a custom sql as my query with parameters on birth_dt and ssn.

 

Parameter 1: birthdate

Parameter 2: s_s_n

https://blog.crossjoin.co.uk/2023/01/29/passing-any-arbitrary-value-from-a-power-bi-report-to-a-dyna...

 

let

 Source = Teradata.Database("MYPROD", [Query = " SELECT

A.NAME AS FNAME,

A.BIRTH_DT AS BDATE,

A.SSN AS SSN

FROM

EMPLOYEE A

WHERE 

A.BIRTH_DT ='"&birthdate&"' AND A.SSN = '"&s_s_n&"' " ] ),

FilterList = if Type.Is(Value.Type(s_s_n),List.Type) then s_s_n else {SSN},

FilteredRows = Table.SelectRows( Source,each List.Contains( FilterList,[SSN]))

in

FilteredRows

 

Can't figure out where I did wrong.

 

Thanks.

1 ACCEPTED SOLUTION
v-ssriganesh
Community Support
Community Support

Hi @rnola16,
Thank you for reaching out to the Microsoft Fabric Community Forum.

You're on the right path using dynamic M query parameters in DirectQuery mode. Since you're passing values like birth_dt and ssn, here are a few ideas that might help troubleshoot:

  • Make sure both parameters are correctly linked to slicers using dummy dimension tables. This is essential for dynamic input from the report UI.
  • Double-check that the names of the parameters you're using throughout the query are consistent mismatched names can cause unexpected behaviour.
  • Confirm that Power BI can fold the filters back to the source system. If the filtering isn't being pushed down to the database, the dynamic behaviour may not work as expected.
  • It's generally recommended to avoid directly embedding parameter values into custom SQL strings for both security and performance reasons. Power BI handles parameters more effectively when they’re passed and processed using native filtering.

If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.

Thank you.

View solution in original post

17 REPLIES 17
v-ssriganesh
Community Support
Community Support

Hi @rnola16,

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.

 

v-ssriganesh
Community Support
Community Support

Hi @rnola16,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 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.

v-ssriganesh
Community Support
Community Support

Hi @rnola16,
Thank you for reaching out to the Microsoft Fabric Community Forum.

You're on the right path using dynamic M query parameters in DirectQuery mode. Since you're passing values like birth_dt and ssn, here are a few ideas that might help troubleshoot:

  • Make sure both parameters are correctly linked to slicers using dummy dimension tables. This is essential for dynamic input from the report UI.
  • Double-check that the names of the parameters you're using throughout the query are consistent mismatched names can cause unexpected behaviour.
  • Confirm that Power BI can fold the filters back to the source system. If the filtering isn't being pushed down to the database, the dynamic behaviour may not work as expected.
  • It's generally recommended to avoid directly embedding parameter values into custom SQL strings for both security and performance reasons. Power BI handles parameters more effectively when they’re passed and processed using native filtering.

If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.

Thank you.

Hi @rnola16,
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please accept it as a solution and give it a 'Kudos' so other community members with similar problems can find a solution faster.
Thank you.

rnola16
Advocate II
Advocate II

Any ideas ?

Deku
Super User
Super User

This section relates to his blank dummy dimensions 

 

FilterList = if Type.Is( Value.Type(SalesOrderNumber), List.Type)

    then SalesOrderNumber else {SalesOrderNumber},

 

If checks if it is a list, if yes return it. If a single value it casts it as a list. These are the values passed through from the report, when user provides values

 

Then filters his table from SQL server, where [SalesOrderNumber] exists in the list from above

 

 #"Filtered Rows" = Table.SelectRows( #"Removed Other Columns", each List.Contains( FilterList, [SalesOrderNumber]

    )


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

The parameter name and the column name are defined with same name and its confusing what is the colum and what is the parameter in here.

rnola16
Advocate II
Advocate II

In the M code from Chris webb, what is the difference between (SalesOrderNumber) , SalesOrderNumber, {SalesOrderNumber} and [SalesOrderNumber] 

 

Thanks.

 

let
  Source = Sql.Database(
    "localhost",
    "AdventureWorksDW2017"
  ),
  dbo_FactInternetSales = Source
    {
      [
        Schema = "dbo",
        Item   = "FactInternetSales"
      ]
    }
    [Data],
  #"Removed Other Columns"
    = Table.SelectColumns(
    dbo_FactInternetSales,
    {
      "OrderDateKey",
      "SalesOrderNumber",
      "SalesOrderLineNumber",
      "SalesAmount"
    }
  ),
  FilterList = if Type.Is( Value.Type(SalesOrderNumber), List.Type)
    then SalesOrderNumber else {SalesOrderNumber},
  #"Filtered Rows" = Table.SelectRows( #"Removed Other Columns", each List.Contains( FilterList, [SalesOrderNumber]
    )
  )
in
  #"Filtered Rows"

 

rnola16
Advocate II
Advocate II

Modified that to include s_s_n.

 

Updated:

let

 Source = Teradata.Database("MYPROD", [Query = " SELECT

A.NAME AS FNAME,

A.BIRTH_DT AS BDATE,

A.SSN AS SSN

FROM

EMPLOYEE A

WHERE 

A.BIRTH_DT ='"&birthdate&"' AND A.SSN = '"&s_s_n&"' " ] ),

FilterList = if Type.Is(Value.Type(s_s_n),List.Type) then s_s_n else {s_s_n},

FilteredRows = Table.SelectRows( Source,each List.Contains( FilterList,[SSN]))

in

FilteredRows

 

Get warning, "This step results in a query that is not supported in DirectQuery mode" on 

FilteredRows = Table.SelectRows( Source,each List.Contains( FilterList,[SSN]))

 

Is it that the function is not recognized by the Teradata ?

 

When I do this, I get a warning " This step results in a query that is not supported in DirectQuery mode."

 

Is this feature not meant for custom SQL query in directquery mode ?

 

Really having a hard time to deal with PBI for a simple task.

 

Thanks.

Question. You are already injecting a filter into native query, although assuming only a single SSN is supplied.The other steps are just filtering again, but allow for a lookup from a list.

Which one should be used?


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

I'm looking to generate results with ssn as parameter  ( can be single entry or multi-value ). The ssn parameter is left blank so users can enter arbitrary values and find their own records.

 

Eg; Select * from Employee where ssn in '"&paramter&"'

You need to pick between the injection of a where clause or use the table.selectcolumns. table.selectcolumns is how Chris is allowing for both single and multiple selections 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

I'm trying to use a simple select statement where users can input their desired value on a parameter. 

Deku
Super User
Super User

Just checking have you created the dummy dimensions for both parameters?


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

yes.

In your filter list shouldn't SSN be s_s_n?


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors