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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
viveknz
New Member

Data outside of date range

I have a customer table that contains customer details along with their last purchase date. I have an area table that is related to customer table by area code. Finally, I have a DateDim table for the dates. I am using a date slicer with relative date as slicer settings. I want to identify customers who haven't purchased within 1 calendar week, 1 month, etc in an area.

I have created a measure to identify the dates outside of the selected value in the date slicer. However it is very slow in performance. Can someone please suggest a better and more efficient way?

Non trading = 
CALCULATE(
    IF(
        MAX(Customer[Last purchase date]) <> SELECTEDVALUE(DateDim[Date]),
        BLANK(), [Last Purchase Date]),
    FILTER(
        ALL(DateDim),
        DateDim[Date] < MIN(DateDim[Date]) || DateDim[Date] > MAX(DateDim[Date]))
)

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @viveknz 

 

Please try this:

Here I create a set of sample:

Customer:

vzhengdxumsft_0-1733709778774.png

DateDim:

vzhengdxumsft_1-1733709804730.png

Make sure that there aren't any relationships between the 2 tables:

vzhengdxumsft_2-1733709873530.png

Then create a measure:

MEASURE =
VAR _Slicer =
    ALLSELECTED ( DateDim[Date] )
RETURN
    IF ( NOT MAX ( 'Customer'[Last purchase date] ) IN _Slicer, 1 )

Add a table visual and drag the measure to the 'Filters on this visual' in the Filters pane, then filter the value of the measure is 1 and click the Apply filter:

vzhengdxumsft_3-1733710094261.png

The result is as follow:

vzhengdxumsft_4-1733710273953.pngvzhengdxumsft_5-1733710283921.png

 

 

Best Regards

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

View solution in original post

5 REPLIES 5
Kedar_Pande
Super User
Super User

@viveknz 

Optimized Measure:

NonTradingCustomers =
VAR MinDate = MIN(DateDim[Date])
VAR MaxDate = MAX(DateDim[Date])
RETURN
CALCULATE(
COUNTROWS(Customer),
FILTER(
Customer,
Customer[Last purchase date] < MinDate || Customer[Last purchase date] > MaxDate
)
)

Add the NonTradingCustomers measure to a card visual to show the total count of non-trading customers for the selected period.
Use Customer[AreaCode] in a table or matrix visual if you need to group the non-trading customers by area.

 

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

powerbiexpert22
Impactful Individual
Impactful Individual

Hi @viveknz ,

is you dax formula giving correct results and the only issue is performance?

are you using import or direct query connection?

what is the size (in MB or GB) of dataset or Power BI file?

is your database perfornace slow?

are you following star schema design in your data model?

can you please share some sample data?

Poojara_D12
Super User
Super User

Hi @viveknz 

Can you please try this DAX:

NonTradingCustomers =
CALCULATE(
    COUNTROWS(Customer),
    FILTER(
        Customer,
        Customer[Last purchase date] < MIN(DateDim[Date]) -- Last purchase is before the slicer range
            || Customer[Last purchase date] > MAX(DateDim[Date]) -- Last purchase is after the slicer range
    )
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Thanks Poojara. How would this enable me to list the name of the customers who haven't purchased outside of the selected date range? I want to list the customer name with their last purchase date.

Anonymous
Not applicable

Hi @viveknz 

 

Please try this:

Here I create a set of sample:

Customer:

vzhengdxumsft_0-1733709778774.png

DateDim:

vzhengdxumsft_1-1733709804730.png

Make sure that there aren't any relationships between the 2 tables:

vzhengdxumsft_2-1733709873530.png

Then create a measure:

MEASURE =
VAR _Slicer =
    ALLSELECTED ( DateDim[Date] )
RETURN
    IF ( NOT MAX ( 'Customer'[Last purchase date] ) IN _Slicer, 1 )

Add a table visual and drag the measure to the 'Filters on this visual' in the Filters pane, then filter the value of the measure is 1 and click the Apply filter:

vzhengdxumsft_3-1733710094261.png

The result is as follow:

vzhengdxumsft_4-1733710273953.pngvzhengdxumsft_5-1733710283921.png

 

 

Best Regards

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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