Customers who have made purchases within the last 90 days

Hi everyone,

I have a bit of a tricky query that I’m getting an error with.

GB Test.pbix (108.7 KB)

I’m trying to create a Calculated table to show customers who have made purchases within the last 90 days.
I’m trying to alter the code below to include a few more rules and filters without the need to use slicers etc:

First, to put this code between a certain period (01/03/2024 to 31/05/2024 for example).

Second, to only include a certain product description (Iphone 15 or item code 5 only for example or any other product).

Third, to exclude STAFF from the Customer Class field in the Customer table.

Last, to only include Tesco from the Chain field in the customer table.

I know you can filter and use slicers, etc but my company are looking for set code that helps to not require slicers etc for the business users so they can see the data straight away.

The code I used below is getting an error - Too many arguments were passed to the AND function. The maximum argument count for the function is 2.

Any idea how to fix this? My code is below and sample PBIX also.

Any help would be greatly appreciated!

Customers with first purchase 90 Days =
FILTER(
ADDCOLUMNS(
ADDCOLUMNS(
ADDCOLUMNS(
SUMMARIZE(
‘Sales Table’,
‘Sales Table’[Customer ID],
“MinTransactionDate” , MIN( ‘Sales Table’[Transaction Date]) ,
“MaxTransactionDate” , MAX(‘Sales Table’[Transaction Date])
),

        "1stTransactionOrNot" , 
        IF( [MinTransactionDate] = [MaxTransactionDate] ,
        "1st Transaction" , "Not the first Transaction")
),

"DaysFromFirstTransaction" , 
IFERROR( INT( TODAY() - [MaxTransactionDate] ),
0)
),

"RegularCustomerOrNot" ,
IF( [DaysFromFirstTransaction] <= 90 ,
"Regular Customer" , "Not a regular Customer" )
),

AND( [RegularCustomerOrNot] = "Regular Customer" ,
NOT ISBLANK( 'Sales Table'[Customer ID] ),
'Sales Table'[Transaction Date] >= DATE(2024, 3, 1) 
&& 'Sales Table'[Transaction Date] <= DATE(2024, 5, 31), 

('Sales Table'[Product Description] = "Iphone 15" 
|| 'Sales Table'[Item Code] = 5), 

'Customer Table'[Customer Class] <> "STAFF", 'Customer Table'[Chain] = "Tesco" ) )

Before you send your question.
Make sure that all details relevant to your question is complete:

  • Your current work-in-progress PBIX file - VERY IMPORTANT
  • A clear explanation of the problem you are experiencing
  • A mockup of the results you want to achieve
  • Your underlying data file

Check out this thread on Tools and Techniques for Providing PBIX Files with Your Forum Questions
Also make sure that your data file contains no confidential information. If it does, click the link above.

*** DELETE THIS MESSAGE IF YOU ARE SURE ALL YOUR DETAILS ARE COMPLETE OR IF THE ABOVE INFORMATION IS NOT APPLICABLE TO YOUR QUESTION.***


Gregg

I stored the conditions in variables.
For two of the variabels I added the tables for checking purposes
delete this tables afterwards, they are not needed.

I’m not a great fan of hard code Item codes, customer Class, customer chain …
but apparently that is what You want ?!
The result of your example is 1 record which you can see in the attached screen shot.
attached also the pbix file where I added the calendar table from Melissa.
Start using this in your reports.
I hope this is what you are looking for

kind regards,
Roger

GB Test possible solution.pbix (314.0 KB)

That’s great, really appreciate that thank you!!

Just one more quick question. How do I create the Calendar Table (Melissa) ? I see no code for a calculated table for it.

Hi there

here is the link to @Melissa Calendar posting
Extended Date Table (Power Query M function) - Power Query / M Code Showcase - Enterprise DNA Forum

Just copy the m code into a blank query

Within the EDNA Dashboard there is a Lab that was setup that fully explains it.
Lab
Dashboard (enterprisedna.co)

there is also a video on it
Dashboard (enterprisedna.co)

I hope this helps.
Keith

Thanks for your help everyone!

Cheers,

Enterprise DNA SUpport Team

1 Like

Thank you for all that Keith! Much appreciated!