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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
anagnostes
Frequent Visitor

Memory issues with DAX filter

Hi,

 

I have a model where I have a Customers table and an Orders Table. I want to add a new mesure in the Customers table where i want to compute the average buying cyle. So i add this DAX mesure:

 

 

    BUYING_CYCLE = 
            AVERAGEX(ORDERS; 
                    DATEDIFF( CALCULATE
                        MAX ( 'ORDERS'[ORDER_DATE] ) ;
                            FILTER(ORDERS; EARLIER('ORDERS'[ORDER_DATE]) >= 'ORDERS'[ORDER_DATE] )
                    ); 'ORDERS'[ORDER_DATE]
                    ; DAY )
            ) 

 

This works fine but it's not correct. I should add a second filter like this:

 

FILTER(ORDERS; EARLIER('ORDERS'[ORDER_DATE]) >= 'ORDERS'[ORDER_DATE] ) && EARLIER('ORDERS'[ID]) <> 'ORDERS'[ID] )

 

But if I add this second expression the query is really slow and the memory gets to 98 plus %.  There aren't a lot of records in the Orders table, like 25000. 

 

Can anybody tell me how can i understand what is happening here?

 

Thank you.

2 REPLIES 2
Baskar
Resident Rockstar
Resident Rockstar

My understanding from your requierment .

 

U have customer table, Order Table.

 

U want to know the Customer average ? am right ?

 

if yes ? do u have relarionship between this two tables right ?

 

then u can use direct average function . i know i misunderstood.

 

Can u please share your sample data, and your expected output i will help u.

 

I think u want to know the Customer Running Average.

Bitwize_PowerBI
Advocate IV
Advocate IV

I think you can do the filter without the earlier() function.

 

try: FILTER(ORDERS; VALUES('ORDERS'[ORDER_DATE]) >= 'ORDERS'[ORDER_DATE] ) && VALUES('ORDERS'[ID]) <> 'ORDERS'[ID] )

 

as you cycle through all of your orders, you could create a calculated column in your orders table to get the 'previous order date'.  You would have to add a condition for 'the same customer':

 

CALCULATE ( 
                        MAX ( 'ORDERS'[ORDER_DATE] ) ;
                             FILTER(ORDERS; EARLIER('ORDERS'[ORDER_DATE]) >= 'ORDERS'[ORDER_DATE] ) && EARLIER('ORDERS'[ID]) <> 'ORDERS'[ID] && EARLIER('CUSTOMER'[ID]) = 'CUSTOMER'[ID])
                     )

 

Regards,

Dries

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.