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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Giorgi1989
Advocate II
Advocate II

Old vs new customer calculated column

Hi,

 

I am trying to create a calculated  column that will consist of two options: 'Old' or 'New customer', based on certain crtieria, which I will provide below:  

 

  • If the customer has sales within last 12 months from the last purchase AND has no sales prior to that, then the customer is 'New'. 
  • If on the othe hand, the customer has sales both within last 12 months as well as months prior to that, then the customer is 'Old'. 

It seems to work fine for the last 12 months (From Sep 2023). But, then some months appear blank, which is not plausible. 

 

Giorgi1989_0-1696609367834.png

 

Please, see my DAX below. I have been brainstorming for quite some time, what might be the reason behind the blank values in that simple matrix above.

 

The sales table has the data of about 5 years in it. 

 

Customer Type =
VAR MAXMonth =
          MAX('Calendar'[date])
VAR Last12Months =
    DATESINPERIOD('Calendar'[date], MAXMonth,-12,MONTH)
VAR Last13to36Months =
    DATESINPERIOD(''Calendar'[date],Date(Year(MAXMonth)-1,Month(MAXMonth), Day(MAXMonth)),-24,MONTH)
RETURN
IF(
    COUNTROWS (
        FILTER (
            'Sales',
            'Sales'[Customer] = EARLIER('Sales'[Customer])
            && 'Calendar'[date] IN Last13to36Months
        )
    ) > 0
    && COUNTROWS (
        FILTER (
            'Sales',
            'Sales'[Customer] = EARLIER('Sales'[Customer])
            && 'Calendar'[date] IN Last12Months
        )
    ) > 0,
    "Repeat customer",
    "Old customer"
)
 
Anyone has an idea what might be wrong? Any inaccuracies in the DAX above, which I am simply overlooking?

Thank you for your help! 
2 REPLIES 2
Giorgi1989
Advocate II
Advocate II

Thank you, but that would not help! 

BeaBF
Super User
Super User

@Giorgi1989  Hi! I'va adjusted the code:

Customer Type =
VAR MAXMonth = MAX('Calendar'[date])
VAR Last12Months = DATESINPERIOD('Calendar'[date], MAXMonth, -12, MONTH)
VAR Last13to36Months = DATESBETWEEN('Calendar'[date], DATE(YEAR(MAXMonth) - 3, MONTH(MAXMonth), DAY(MAXMonth)), DATE(YEAR(MAXMonth) - 1, MONTH(MAXMonth), DAY(MAXMonth)))
RETURN
IF (
COUNTROWS (
FILTER (
'Sales',
'Sales'[Customer] = EARLIER('Sales'[Customer])
&& 'Calendar'[date] IN Last13to36Months
)
) > 0
&& COUNTROWS (
FILTER (
'Sales',
'Sales'[Customer] = EARLIER('Sales'[Customer])
&& 'Calendar'[date] IN Last12Months
)
) > 0,
"Old customer",
"New customer"
)

BBF

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors