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
Anonymous
Not applicable

DISTINCTCOUNT taking up too much memory

Hi, I have a distinctcount calculated column on a summarized table "Summary" which is taking too long to compute (my computer runs out of memory before it can finish). Please can someone help me find a way to make this work more efficiently? Thank you.

 

DISTINCTCOUNT_USERS =
calculate(distinctcount(Table1[UserID]),
filter(Table1,Table1[Code]=Summary[Code]),
filter(Table2,Table2[Status]="Completed"),
filter(Table2,Table2[EventDate]=Summary[Date]))

(Table1 and Table2 are related)
1 ACCEPTED SOLUTION

Hi @Anonymous 

 

You can use TREATAS as below if it's still too slow, consider moving the calculation to Power Query.

 

DISTINCTCOUNT_USERS_ = 
VAR __filter = { ( Summary[Code], Summary[Date], "Completed" ) }
RETURN 
CALCULATE(
    DISTINCTCOUNT( Table1[UserID] ),
    TREATAS( 
        __filter, 
        Table1[Code], Table2[EventDate], Table2[Status]
    )
)

 

 

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous ,
Try if this can work better

countx(summarize(calculatetable(Table1,
filter(Table1,Table1[Code]=Summary[Code]),
filter(Table2,Table2[Status]="Completed"),
filter(Table2,Table2[EventDate]=Summary[Date])),Table1[UserID])[UserID])
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @Anonymous 

 

You can use TREATAS as below if it's still too slow, consider moving the calculation to Power Query.

 

DISTINCTCOUNT_USERS_ = 
VAR __filter = { ( Summary[Code], Summary[Date], "Completed" ) }
RETURN 
CALCULATE(
    DISTINCTCOUNT( Table1[UserID] ),
    TREATAS( 
        __filter, 
        Table1[Code], Table2[EventDate], Table2[Status]
    )
)

 

 

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

Hi @amitchandak are you sure the brackets etc. are in the right place? Power BI doesn't like that code

@Anonymous  one , was missing

countx(summarize(calculatetable(Table1,
filter(Table1,Table1[Code]=Summary[Code]),
filter(Table2,Table2[Status]="Completed"),
filter(Table2,Table2[EventDate]=Summary[Date])),Table1[UserID]),[UserID])
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.