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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
WRA_LT
Regular Visitor

DirectQuery error when loading visualization from PostgreSQL table using Dynamic M query parameter

I'm trying to create a line graph in Power BI desktop from an on-premises PostgreSQL database table via DirectQuery while using a Dynamic M query parameter, and the visualization fails to load. I get the following error message when I click the See details link:

 

powerbi_error01.JPG

 

I'm able to successfully load the table while using the Dynamic M query parameter in Power Query editor (see image below), so I don't understand why it fails to load in the visualization. Regarding the query parameter, I created a new table in Power BI that lists some example project ID's to use as a slicer and then created matching parameters using instructions from this Medium article:

 

powerbi_error02.JPG

 

So, my question is if Power BI visualizations support PostgreSQL data pulled via DirectQuery with Dynamic M parameters. Assuming they do, how can I resolve this error? And if not, what databases do support this functionality?

 

Thank you in advance!

1 ACCEPTED SOLUTION

Instead of using the Query option directly I recommend you try the Value.NativeQuery variation. That may make it easier to consume the parameter.

View solution in original post

4 REPLIES 4
WRA_LT
Regular Visitor

I'm happy to report that using Value.NativeQuery with the [EnableFolding = true] option enabled resulted in the visualization loading successfully:

 

let
    Source = PostgreSQL.Database("Insert IP address here", "Insert database name here"),
    Query = Value.NativeQuery(
        Source,
        "SELECT * FROM foo1.test WHERE proj = " & Text.From(ProjID_Parameters) & "",
        null,
        [EnableFolding = true])
in
    Query

 

Before including the EnableFolding option, the table would load fine in Power Query Editor but the same visualization error occurred. I stumbled upon a blog post that discussed passing parameters via query folding, along with why EnableFolding needed to be included.

 

Thanks for the assistance!

WRA_LT
Regular Visitor

The SQL statment (as it's written in Power Query) is correct, because even though the value in the proj column is being called via the Text.From function, it's actually an integer and not a text value. I have to use the Text.From function because the entire SQL query is itself a string, so using the Number.From function results in an error due to the conflicting data types:

 

powerbierrorsqlquery.JPG

 

Out of curiosity, I tried both of the following lines of code in DBeaver, and they both successfully loaded the table. I assumed that using the single quote around an integer value would result in it being cast as a text datatype and result in an error, but it apparently doesn't:

 

select * from foo1.test where proj = '12345';

select * from foo1.test where proj = 12345;

 

I've also confirmed that inserting a single quote before and after the double quote while using the Text.From function will result in the table being loaded just the same as the original SQL query, but leads to the same error in the visualization. So, I'm still left with the same error as before regardless if I use a sinqle quote or not.

 

Thank you for the response.

Instead of using the Query option directly I recommend you try the Value.NativeQuery variation. That may make it easier to consume the parameter.

lbendlin
Super User
Super User

Your SQL code is missing the single quotes around the text value.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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