Forum Discussion

Pinoo39's avatar
Pinoo39
Frequent Visitor
5 years ago

New Customers DAX

Hi all,

 

I'm using "DaxPatterns"  article to calculate New Customers but couldnt find a way to filter some customers first. I need to filter Customers List based on an attribute (e.g. "Status" column in Sales Table) then use it in the formula.
I trid to define a variable like the following but it didn't work

VAR CustomersList =
CALCULATETABLE(VALUES(Sales[CustomerKey]), FILTER(Sales, Sales[type] in {7, 8} && Sales[status] in {4, 7}))
 

This is the Code :

 

Date New Customer :=
CALCULATE (                   -- The first sale is
    MIN ( Sales[Order Date] ), -- the MIN of the order date
    ALLEXCEPT (                 
        Sales,                -- ignoring any filter
        Sales[CustomerKey],   -- other than the customer
        Customer
    )
)

 

AND then number of New Customers is :

 

# New Customers :=
VAR CustomersWithNewDate =
    CALCULATETABLE (                       -- Prepares a table that
        ADDCOLUMNS (                       -- for each customer contains
            VALUES ( Sales[CustomerKey] ), -- the date of their first puchase
            "@NewCustomerDate", [Date New Customer]
        ),
        ALLEXCEPT ( Sales, Customer )
    )
VAR NewCustomers =
    FILTER (                              
        CustomersWithNewDate,              -- Filters the customers
        [@NewCustomerDate]                 -- whose new customer date
            IN VALUES ( 'Date'[Date] )     -- falls within the current period
    )
VAR Result =                               -- The count of the new customers
    COUNTROWS ( NewCustomers )             -- does not use the Sales table
RETURN
    Result


Any idea on doing that ?

6 Replies