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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Diego_Vialle
Helper II
Helper II

DAX - Measure for customers who never bought, but started buying in the last 2 months

Good afternoon, I need some help. I need to create an invoice count measure for customers who have never purchased and have purchased in the last two months. I have the two measurements below:

 

Bimonthly order frequency = CALCULATE(DISTINCTCOUNT(SBOPRODMS[Customer]),and(SBOPRODMS[invoice date]>=TODAY()-60,SBOPRODMS[document]="outgoing invoice"))

 

Total customers = CALCULATE(DISTINCTCOUNT(SBOPRODMS[Customer]),and(SBOPRODMS[invoice date]>=TODAY()-365,SBOPRODMS[document]="outgoing invoice"))

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Diego_Vialle 

You may try

New Customers =
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            < TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        AND (
            SBOPRODMS[invoice date]
                >= TODAY () - 60,
            SBOPRODMS[document] = "outgoing invoice"
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )

View solution in original post

12 REPLIES 12
tamerj1
Super User
Super User

Hi @Diego_Vialle 

You may try

New Customers =
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            < TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        AND (
            SBOPRODMS[invoice date]
                >= TODAY () - 60,
            SBOPRODMS[document] = "outgoing invoice"
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )

Thank you very much friend, the formula worked correctly. They have now requested the invoice value of each customer, the measure for invoice is: NET Value | NF = CALCULATE([NET Value],SBOPRODMS[Document]="Outgoing invoice"). How do I implement this data in the bimonthly customers formula??

@Diego_Vialle 

Are you trying to calculate the net value of the customers we have calculated in the previous measure? If so you may try

NET Value | NF =
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            < TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            >= TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
RETURN
    CALCULATE ( [NET Value], EXCEPT ( AllNewCustomers, AllOldCustomers ) )

Exactly, but when I insert the measure as a matrix column, it brings customers outside of what we calculated in the previous measure. The columns are in Portuguese but I believe you understand based on the formula.Erro.png

Erro 2.png

@Diego_Vialle 

This is not correct 

B0221D5E-49E3-4740-B32D-A5E103CE92DA.jpeg

I used your previous suggestion.

@Diego_Vialle 
You are referencing a table! In my measure I am referencing another measure [Net Value]. I am using CALCULATE you are using COUNTROWS!

Because it is requesting a table and not measure...

 

Erro.png

@Diego_Vialle 

It is CLACULATE not COUNTROWS

Oh sorry, I hadn't seen Calculate. I changed it to Calculate and entered the invoice measure. However, it brings up all the clients, ignoring the previous calculation that we made only for the bimonthly clients.

 

Erro.png

@Diego_Vialle 

But are getting correct values?

you can force the fiter in the filter pane for the previous measure set as "is not blank". Also try to iterate over the table but modt probably you will get wrong results but worth try then we can modify incuding all coulmns in the visual with iteration table

NET Value | NF =
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            < TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Customer] ),
        SBOPRODMS[invoice date]
            >= TODAY () - 60,
        SBOPRODMS[document] = "outgoing invoice"
    )
RETURN
    SUMX ( EXCEPT ( AllNewCustomers, AllOldCustomers ), [NET Value]  )

 

The New Bimonthly Customers column does not need to add the values, it is enough to bring the invoice value of each bimonthly customer.

 

Diego_Vialle_0-1649787227898.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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