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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
nima_mlk
Frequent Visitor

We couldn't fold the expression to the data source. PostgreSQL DirectQuery

I have set up a DirectQuery connection with a PostgreSQL database hosted on AWS. I'm able to navigate through the tables and views of my database, and also build basic transformations and measures in Power BI Desktop. I can build some visualizations on top of it as well, however some of the columns cause the following error when used in visualizations:

 

OLE DB or ODBC error: [Expression.Error] We couldn't fold the expression to the data source. Please try a simpler expression..

 

I tried to isolate the issue and understand the cause. In particular, any Count Distinct aggregation in the "value" fields of visualiztions causes the above error. Even when I create a new measure with COUNTDISTINCT, the same problem presists. Curiously, a new measure with COUNTDISTINCTNOBLANK works fine, but I don't have any null or blank values in the column that I'm counting.

 

Is this a bug? Is there a workaround?

 

PS1: I do NOT have a custom SQL query on the connector

PS2: Even actually complicated queries work well, e.d Percentage of Grant Total Averages, grouped by categories.

PS3: This might be related to this issue, but that one is related to the Amazon Redshift data source.

 

Power BI Desktop Version: 2.73.5586.561 64-bit (September 2019)

Npgsql-4.0.9

3 REPLIES 3
ShaWo
Advocate I
Advocate I

I'm experiencing the same issue with AWS RDS hosted PostgreSQL. Some tables work fine and some complicated measures do go through quite easily, but on some tables or views there seem to be a problem. Some basic queries like querying the store names from a table with 17k records cause an error. That shouldn't be an issue. When I run a similar query in the db theres no errors. Theres only 4 distinct values in that column and if I do a count or distinct count of those values then it works. All the summarizable fields in the that table work fine but text columns don't. On a different table some of the text columns work and some don't.

I actually continued the tests and one weird thing came up. One of the connected tables that I have the problem with is a view in the database. There's a store name and product name fields in the view that aren't working and giving me the aformentioned error message. I took the ddl from that view and created a new query to the database with that views exact SQL statement and surprise surprise those two fields don't give any errors.

What on earth is going on?

v-chuncz-msft
Community Support
Community Support

@nima_mlk 

 

To get faster and better technical support for this issue, you may directly create a support ticket.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.