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
Anonymous
Not applicable

Identify no purchase after specific date or no purchase at all

Hi,

 

I want to identify the customers that did not have a purchase on a certain product group for longer than 4 months or not at all.

There is already a topic regarding this: Topic I created

In this topic I thought I found the answer, however I am running in to a new problem.

 

I would like to identify the customers that did not have a purchase on a certain product group for more than 4 months or not at all. Due to merged tables with quarterly data it could happen A customer has no purchase on a product group, however further down the table it has.

 

I am using the following data:

 

CustomerProduct groupproductdate purchaseAmountPriceNo regular purchase
Customer AA     
Customer AA     
Customer BA     
Customer BB     
Customer AAAA11-8-201825 
Customer AAAB11-8-2018528 
Customer ABBA11-8-2018445 
Customer ABBB11-8-201833688 
Customer ABBB25-8-2018245 
Customer AC    No purchase
Customer AD    No purchase
Customer BAAA21-7-2018268 
Customer BAAB21-7-2018633 
Customer BAAB4-8-2018478 
Customer BAAD4-8-2018893 
Customer BBBA4-8-2018454 
Customer BBBB4-8-2018212 
Customer BC    No purchase
Customer BDDA21-12-2017885 
Customer BDDB11-1-2018643No purchase
Customer CA    No purchase
Customer CBBA6-4-2016493 
Customer CBBB11-4-201655No Purchase
Customer CCCA3-10-2016672 
Customer CCCB6-10-2016447 
Customer CCCC11-10-2016832No purchase
Customer AA     
Customer AA     
Customer AB     
Customer AB     
Customer AB     
Customer AC     
Customer AD     
Customer AE    No purchase
Customer AE     
Customer AE     
Customer AF    No purchase
Customer AF     
Customer AF     
Customer BA     
Customer BB     
Customer BC     
Customer BD     
Customer BE    No purchase


In my previous topic we identified the following DAX:

 

NEW = 
VAR minIndex =
    CALCULATE (
        MIN ( Table3[Index] ),
        ALLEXCEPT ( Table3, Table3[Product group], Table3[Customer] )
    )
VAR lastestDate =
    CALCULATE (
        MAX ( Table3[date purchase] ),
        ALLEXCEPT ( Table3, Table3[Product group], Table3[Customer] )
    )
VAR PGHasPur =
    CALCULATETABLE (
        VALUES ( Table3[Product group] ),
        FILTER ( ALLEXCEPT(Table3, 'Table3'[Customer] ), Table3[date purchase] >= EDATE ( TODAY (), -4 ) )
    )
RETURN
    IF (
        ISBLANK ( [date purchase] ),
        IF ( [Index] = minIndex, "No purchase", BLANK () ),
        IF (
            NOT [Product group] IN PGHasPur
                && [date purchase] = lastestDate,
            "No purchase",
            BLANK ()
        )
    )

 

The result in powerBI:

Capture.PNG

 

As you can see the first row is marked as "no purchase", however row 3 and 4 indicate there has been a purchase in the last 4 months on product group A.

 

I hope someone can help me finding a solution.

If any further questions please do not hesitate to ask.

 

Kind regards,

Guido

 

 

6 REPLIES 6
Anonymous
Not applicable

 

Hi,

 

I have pasted your sample data and added a calculated column to determin if the customer has purchased a product group which will give 3 outputs

 

1) Not purchased ever.

2) Not purchased within last four months.

3) Purchased within last four months.

 

Can you try this?

 

New =
IF (
    SUMX (
        FILTER (
            ALL ( Table1 ),
            EARLIER ( Table1[Customer] ) = Table1[Customer]
                && EARLIER ( Table1[Product group] ) = Table1[Product group]
        ),
        Table1[Amount]
    )
        = 0,
    "Not purchased ever",
    IF (
        SUMX (
            FILTER (
                ALL ( Table1 ),
                EARLIER ( Table1[Customer] ) = Table1[Customer]
                    && EARLIER ( Table1[Product group] ) = Table1[Product group]
                    && Table1[date purchase] >= EDATE ( TODAY (), -4 )
            ),
            Table1[Amount]
        )
            = 0,
        "Not purchased in last 4 months",
        "Purchased within 4 months"
    )
)

 

Anonymous
Not applicable

@Anonymous

 

Could you think of a way to make that happen?

 

Regards,

Guido

Anonymous
Not applicable

Hi,

 

Can you clarify the follwing..

 

1) Do you want the results in a new calculated table or in the same table itself.

 

2) In your sample data you have posted, the "Index" column is not there, but in the previous formula it has been used. Can you post the sample data again with all the relevant columns included. 

 

3) There are 3 scenarios:

    a) Customer has not purchased the product group ever.

    b) Customer has not purchased the product group within last four months.

    c) Customer has purchased the product within last months.

 

Once you clarify these things, I think we can bring the desired output.

 

In each of these scenarios (a,b or c), what is the value you want in the "New" column?

 

 

 

 

Anonymous
Not applicable

Hi @Anonymous

 

Thanks for you reply 

 

1) I would like the results in the same table (column "no regular purchase" is the desired custom column)

 

2) The index colomn is added in the query editor. I have added the index colomn in the sample data below.

 

3) There are indeed 3 scenarios

 a) The result would be: "No purchase". However, this will occure only once per product group per customer

 b) The result would be: "No purchase". However, this will occure only once per product group per customer

 c) The result would be: blank 

 

The outcome would be as column "no regular purchase" marked in red:

 

CustomerProduct groupproductdate purchaseAmountPriceIndexNo regular purchase
Customer AA    0 
Customer AA    1 
Customer BA    2 
Customer BB    3 
Customer AAAA11-8-2018254 
Customer AAAB11-8-20185285 
Customer ABBA11-8-20184456 
Customer ABBB11-8-2018336887 
Customer ABBB25-8-20182458 
Customer AC    9No purchase
Customer AD    10No purchase
Customer BAAA21-7-201826811 
Customer BAAB21-7-201863312 
Customer BAAB4-8-201847813 
Customer BAAD4-8-201889314 
Customer BBBA4-8-201845415 
Customer BBBB4-8-201821216 
Customer BC    17No purchase
Customer BDDA21-12-201788518 
Customer BDDB11-1-201864319No purchase
Customer CA    20No purchase
Customer CBBA6-4-201649321 
Customer CBBB11-4-20165522No Purchase
Customer CCCA3-10-201667223 
Customer CCCB6-10-201644724 
Customer CCCC11-10-201683225No purchase
Customer AA    26 
Customer AA    27 
Customer AB    28 
Customer AB    29 
Customer AB    30 
Customer AC    31 
Customer AD    32 
Customer AE    33No purchase
Customer AE    34 
Customer AE    35 
Customer AF    36No purchase
Customer AF    37 
Customer AF    38 
Customer BA    39 
Customer BB    40 
Customer BC    41 
Customer BD    42 
Customer BE    43No purchase

 

Hope this will make it more clear.

If any questions please ask.

 

Kind regards,

Guido

Anonymous
Not applicable

@Anonymous

 

Can you find a solution?

 

Regards,

Guido

Anonymous
Not applicable

Hi @Anonymous,

 

Thanks for your reply.

I would prefer to have only 1 mark per product group per customer as shown in the other DAX.

 

Regards,
Guido

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.