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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sbuster
Helper I
Helper I

Query optimization assistance

Hello,
I am trying to see if there is a way to optimize the measure in the sample attachment.  The model details an asset (automobile) with events (EventFacts) on a given date.  Each automobile may or may not be associated with a configuration (AssetEventMapping). 

What I would like is a distinct count of assets by day (see DateTable) only if the asset has a configuration associate in the AssetEventMapping table.

 

The model details below show example tables & records with the desired result.  As can be seen, assets 6 and 7 do not show up in daily count because they do not contain a record in the mapping table (filtered out via the "in distinct" portion of hte measure).

 

This measure works fine with small dataset, but my real dataset contains millions of records and this query is taking ~5 seconds.

 

Thanks

 

Tables:

sbuster_0-1681833017769.png

 

Measure:

Count of Assets Reporting =
    calculate(
        DISTINCTCOUNT(EventFacts[AssetId]),
        FILTER(
            EventFacts,
            EventFacts[AssetID] in (distinct(AssetEventMapping[AssetID]))
        )
    )
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @sbuster 

Please try

Count of Assets Reporting =
COUNTROWS (
DISTINCT (
SELECTCOLUMNS (
FILTER (
EventFacts,
EventFacts[AssetID] IN ( DISTINCT ( AssetEventMapping[AssetID] ) )
),
"@AssetID", EventFacts[AssetId]
)
)
)

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @sbuster 

Please try

Count of Assets Reporting =
COUNTROWS (
DISTINCT (
SELECTCOLUMNS (
FILTER (
EventFacts,
EventFacts[AssetID] IN ( DISTINCT ( AssetEventMapping[AssetID] ) )
),
"@AssetID", EventFacts[AssetId]
)
)
)

Thanks for you response, that improved performance significantly!


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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