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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
PhMeDie
Helper I
Helper I

Dax Formula Optimization - Counting transactions based on two facts

Hi,

a quick question to the Pros.

I need the number of transactions for all days on which we had recorded visitor footfall in our stores. Information is stored in two tables - Sales and Footfall. The two facts are linked through two common tables (Store and Calendar).

Do you see any way to speed up this measure?

 

Counting on your help!

 

Cheers.

 

Transactions = CALCULATE (
        CALCULATE (
            DISTINCTCOUNTNOBLANK ( Sales[Transaction key] )            
        ),
        FILTER ( Sales, Footfall[Footfall] > 0 )
    )

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The golden rule of DAX says: "You should NEVER filter a table when you can filter a column." One of the reasons is... speed. You are filtering the full expanded(!!!) table Sales and put it all as a filter. This is one of the worst things you can do in DAX. Instead, you should always filter columns only.

// Assumption is that Store and Calendar
// are dimensions connected to 2 fact
// tables, Sales and Footfall, and the
// connection in 1:* and the filtering
// is one-way.

Transactions =
var __DaysAndStoresWithFootfall =
	CALCULATETABLE(
		SUMMARIZE(
			Footfall,
			Store[StoreID],
			Calendar[Date]
		),
		// No columns from fact tables
		// should ever be exposed to
		// the end user. If you do
		// expose them (very bad),
		// you have to wrap this condition
		// in KEEPFILTERS.
		Footfall[Footfall] > 0
	)
var __result =
	CALCULATE (
		// Why not DISTINCTCOUNT?
		DISTINCTCOUNTNOBLANK ( Sales[Transaction key] ),
		__DaysAndStoresWithFootFall,
		ALL( Stores ),
		ALL( 'Calendar' )
	)
return
	__result

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

The golden rule of DAX says: "You should NEVER filter a table when you can filter a column." One of the reasons is... speed. You are filtering the full expanded(!!!) table Sales and put it all as a filter. This is one of the worst things you can do in DAX. Instead, you should always filter columns only.

// Assumption is that Store and Calendar
// are dimensions connected to 2 fact
// tables, Sales and Footfall, and the
// connection in 1:* and the filtering
// is one-way.

Transactions =
var __DaysAndStoresWithFootfall =
	CALCULATETABLE(
		SUMMARIZE(
			Footfall,
			Store[StoreID],
			Calendar[Date]
		),
		// No columns from fact tables
		// should ever be exposed to
		// the end user. If you do
		// expose them (very bad),
		// you have to wrap this condition
		// in KEEPFILTERS.
		Footfall[Footfall] > 0
	)
var __result =
	CALCULATE (
		// Why not DISTINCTCOUNT?
		DISTINCTCOUNTNOBLANK ( Sales[Transaction key] ),
		__DaysAndStoresWithFootFall,
		ALL( Stores ),
		ALL( 'Calendar' )
	)
return
	__result

 

Pragati11
Super User
Super User

Hi @PhMeDie ,

 

Try following:

Transactions = CALCULATE (
            DISTINCTCOUNTNOBLANK ( Sales[Transaction key] ),
        FILTER ( Sales, Footfall[Footfall] > 0 )
    )

 

Thanks,

Pragati 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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.