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
jaime_parra
New Member

Directquery limitation summarize

Hi,

 

Context: 

I have a table with 7 billion rows in bigquery, the table is partitioned and clustered and performs well when sending queries.

I'm trying to get the number of unique users based on a certain condition and the following SQL syntax works perfectly.

 

SELECT
  COUNT(DISTINCT users) AS cnt_users
FROM (
  SELECT
    users,
    AVG(transactions) AS transactions
  FROM
    `project.dataset.canales`
  WHERE
    Date BETWEEN '2023-10-01' AND '2023-11-05'
  GROUP BY
    users)
WHERE
  transactions BETWEEN 15 AND 25;


The result is one row with the value and the query runs in 2-3 seconds.

jaime_parra_0-1704471818605.png


When translate this query to dax:

light_users = 
VAR _users =
    SUMMARIZECOLUMNS (
        canales[users],
        "avg_trx", AVERAGE ( canales[transactions] )
    )
VAR _filter =
    FILTER ( _users, [avg_trx] >= 15 && [avg_trx] <= 25 )
RETURN
    COUNTROWS ( _filter )

The result in power bi is

jaime_parra_1-1704471913961.png

Looking at the query created by Dax in bigquery I can see that Dax created a temp table but the quantity is 1+ million records

jaime_parra_2-1704472224857.png

 

The table returns to Power BI to make the final calculation. 

So, How can I calculate all directly in the source and solve the problem with the returned rows?

 

I tried using vars, without vars and nothing works for me.

Thanks

4 REPLIES 4
v-kongfanf-msft
Community Support
Community Support

Hi @jaime_parra ,

 

In your DAX expression, you are using SUMMARIZECOLUMNS, which may generate intermediate tables with detailed information for subsequent calculations. In some cases, this can lead to poor performance, especially when working with large datasets.


One way to optimize DAX queries is to use a combination of CALCULATETABLE and VALUES. the idea is to create a filtered table directly in the source and reduce the number of rows before bringing it into Power BI for the final computation.

Try formula like below:

light_users = 
CALCULATE (
    COUNTROWS (
        VALUES ( canales[users] )
    ),
    FILTER (
        ALL ( canales ),
        canales[Date] >= DATE ( 2023, 10, 1 ) &&
        canales[Date] <= DATE ( 2023, 11, 5 ) &&
        AVERAGE ( canales[transactions] ) >= 15 &&
        AVERAGE ( canales[transactions] ) <= 25
    )
)

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi @v-kongfanf-msft 

 

I have made the corresponding tests and different variations in the code. However, the result obtained in the query is blank.

 

jaime_parra_0-1704893825592.png

When testing and validating what the code does in the dwh I see that it creates the following:

jaime_parra_1-1704893883850.png

The problem observed with this metric is:

 

  1. It does not consider the date filter, so the sum and count have them over the entire base.
  2. Although it returns two values, in Power BI it does not display them but leaves them blank.
  3. It is not applying the average filter either, so even when modifying the metric it is not generating the correct values.

Thank you very much for your collaboration, in case of any other suggestions I will be very attentive.

 

Regards

tamerj1
Super User
Super User

Hi @jaime_parra 

try without variables

light_users =
COUNTROWS (
FILTER (
SUMMARIZE (
Cancels,
canales[users],
"@avg_trx", AVERAGE ( canales[transactions] )
),
[@avg_trx] >= 15
&& [@avg_trx] <= 25
)
)

Hi @tamerj1 

I told you that I did the test with the DAX you sent me and it still generates the same in the data source. So the problem persists.

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.