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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Antmkjr
Helper V
Helper V

New Customer DAX formula

https://drive.google.com/file/d/1ulGkZ0whCkSV0yAdHQ5Hr6P7KoxYROFb/view?usp=sharing

 

In the attached file, I am using the below formulas to check if it is a new customer for a particular year, based on Customer ID and Account No seperately

 

New Customer or not Customer ID =
VAR
    Customers = VALUES( Sales[Customer ID] )
RETURN
CALCULATE( DISTINCTCOUNT(sales [Customer ID]),
    FILTER(
        Customers,
        CALCULATE( COUNTROWS( Sales ),
            FILTER( ALL( Dates ), Dates[Date] < MIN( Dates[Date] ) ) ) = 0 ) )
 
 
New Customer or Not using Account =
VAR
    Accountno = VALUES( Sales[Accountno] )
RETURN
CALCULATE( DISTINCTCOUNT(Sales[Accountno]),
    FILTER(
        Accountno,
        CALCULATE( COUNTROWS( Sales ),
            FILTER( ALL( Dates ), Dates[Date] < MIN( Dates[Date] ) ) ) = 0 ) )

 

 

But I want to re calculate this logic to check if Either Customer ID is existing OR Account No is existing in previous year, then consider it as a new customer. ie. to combine the above formulas in a single formula.

So that cases like below are covered. in this example we need to check either Customer ID is existing in previous year or Account No is existing in previous year.

 

AnuTomy_0-1656755722259.png

 

Link to pbix attached.

 

How to restructure the formula for this?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Antmkjr 

 

You can try the following methods.

Column:

New Customers? = 
IF (
    YEAR ( [Purchase Date] )
        = YEAR (
            CALCULATE (
                MIN ( Sales[Purchase Date] ),
                FILTER ( Sales, [Customer ID] = EARLIER ( Sales[Customer ID] ) )
            )
        ),
    1,
    0
)
New Customers? = 
IF (
    YEAR ( [Purchase Date] )
        = YEAR (
            CALCULATE (
                MIN ( Sales[Purchase Date] ),
                FILTER ( Sales, [Customer ID] = EARLIER ( Sales[Customer ID] ) )
            )
        ),
    1,
    0
)

 

vzhangti_0-1657095868202.png

The next judgments about your old and new accounts can be based on these two columns.

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Antmkjr 

 

You can try the following methods.

Column:

New Customers? = 
IF (
    YEAR ( [Purchase Date] )
        = YEAR (
            CALCULATE (
                MIN ( Sales[Purchase Date] ),
                FILTER ( Sales, [Customer ID] = EARLIER ( Sales[Customer ID] ) )
            )
        ),
    1,
    0
)
New Customers? = 
IF (
    YEAR ( [Purchase Date] )
        = YEAR (
            CALCULATE (
                MIN ( Sales[Purchase Date] ),
                FILTER ( Sales, [Customer ID] = EARLIER ( Sales[Customer ID] ) )
            )
        ),
    1,
    0
)

 

vzhangti_0-1657095868202.png

The next judgments about your old and new accounts can be based on these two columns.

 

Best Regards,

Community Support Team _Charlotte

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

Antmkjr
Helper V
Helper V

@amitchandak @tamerj1 anyone pls?

daXtreme
Solution Sage
Solution Sage

Hi @Antmkjr 

 

1. Is each AccountD associated with a customer?

2. How many different AccountID's can a customer have?

3. Can 2 different customers share an account?

1. Is each AccountD associated with a customer?  -- Yes

2. How many different AccountID's can a customer have? -- Mostly 1, but not always, so we want to check either Cust ID is matching OR Account No is matching

3. Can 2 different customers share an account? -- No

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors