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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
eddysern
Frequent Visitor

Modify self-generated SQL Query by visual components

Good morning, everybody.

In a DirectQuery report, using Performance Analyzer, the SQL statement (query) that PowerBI sends to the database to display the visuals has been captured. This query contains certain statements that affect performance and response time.

For example, for a stacked bar chart, use the CAST and TOPfunctions. If I test the query by running it directly in the database without modifying anything, it lasts approximately 2.55 seconds. If I modify the query by removing the CAST and TOP functions, the same dataset is obtained, but in a time of 0.37 seconds (almost 7 times faster).

Is it possible to modify the statement (or query SQL) that Power BI autogenerates and sends to the database to get the dataset and build the visual component?.

Thank you in advance for your feedback.

This is the query that self-generates. Runs in 2.55 seconds. Use TOP and CAST.
Select
TOP 1000001 "t1"." estado_cliente",
CAST(COUNT("t1"." codigo_cliente") AS BIGINT)
AS "a0"
FROM
(

SELECT
CAST("codigo_cliente" AS VARCHAR(4000))
AS "codigo_cliente",
CAST("estado_cliente" AS VARCHAR(4000))
AS "estado_cliente"
FROM
(
(select "$Table"." apellidos_cliente" as "apellidos_cliente",
"$Table"." nombres_cliente" as "nombres_cliente",
"$Table"." direccion_cliente" as "direccion_cliente"
from "Base_datos"." tabla_clientes" "$Table")
)
AS "t1"
)
AS "t1"
GROUP BY "t1"." estado_cliente"


If I remove the CAST and TOP functions. Runs in 0.37 seconds. Removing TOP and CAST.
Select
"t1"." estado_cliente",
COUNT("t1"." codigo_cliente")
AS "a0"
FROM
(

SELECT
"codigo_cliente"
AS "codigo_cliente",
"estado_cliente"
AS "estado_cliente"
FROM
(
(select "$Table"." apellidos_cliente" as "apellidos_cliente",
"$Table"." nombres_cliente" as "nombres_cliente",
"$Table"." direccion_cliente" as "direccion_cliente"
from "Base_datos"." tabla_clientes" "$Table")
)
AS "t1"
)
AS "t1"
GROUP BY "t1"." estado_cliente"

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Raise this as an Idea on the ideas page.  Not currently possible to impact any of the folded queries.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Raise this as an Idea on the ideas page.  Not currently possible to impact any of the folded queries.

Thank you very much @lbendlin . I will do so.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.