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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Identify no purchase after specific date or no purchase at all

Hi,

 

I would like to create a calculated column, which identifies if a "product group" has not been purchased in the last 4 months or have never been purchased at all.

 

I have the following date table (example) with the desired calculated column in red:

CustomerProduct group productdate purchaseAmountPriceNo regular purchase
Customer AAAA11-may-1825 
Customer AAAB11-may-18528 
Customer ABBA11-may-18445 
Customer ABBB11-may-1833688 
Customer ABBB25-may-18245 
Customer AC    No purchase
Customer AD    No purchase
Customer BAAA21-apr-18268 
Customer BAAB21-apr-18633 
Customer BAAB04-may-18478 
Customer BAAD04-may-18893 
Customer BBBA04-may-18454 
Customer BBBB04-may-18212 
Customer BC    No purchase
Customer BDDA21-dec-17885 
Customer BDDB11-jan-18643No purchase
Customer CA    No purchase
Customer CBBA6-apr-18493 
Customer CBBB11-apr-1855 
Customer CCCA24-may-16672 
Customer CCCB06-oct-16447 
Customer CCCC21-feb-17832No purchase

 

The difficulty for me lies in the fact that if a product group has not been purchased in the last 4 months only the last purchase must be marked as "No purchase"

 

I hope someone can help me creating the right DAX

 

Regards,

Guido

1 ACCEPTED SOLUTION

We need to make a few changes indeed. Try the formula below please.

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 ()
        )
    )

Best Regards,

Dale

Community Support Team _ Dale
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

13 REPLIES 13
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi Guido,

 

Try this formula please.

Column =
VAR lastestDate =
    CALCULATE (
        MAX ( Table1[date purchase] ),
        ALLEXCEPT ( Table1, Table1[Product group] )
    )
VAR PGHasPur =
    CALCULATETABLE (
        VALUES ( Table1[Product group] ),
        FILTER ( ALL ( 'Table1' ), Table1[date purchase] >= EDATE ( TODAY (), -4 ) )
    )
RETURN
    IF (
        ISBLANK ( [Amount] ),
        "No purchase",
        IF (
            NOT [Product group] IN PGHasPur
                && [date purchase] = lastestDate,
            "No purchase",
            BLANK ()
        )
    )
Identify_no_purchase_after_specific_date_or_no_purchase_at_all

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft

 

Thank you very much for your help.

 

The formula works almost perfect. However, I am using a merged table and therfore it could happen that an empty product group appears multimple times. In this case I would like to have a "no purchase" only once

 

I'll try to clarify with data:

CustomerProduct group productdate purchaseAmountPriceNo regular purchase
Customer AAAA11-may-1825 
Customer AAAB11-may-18528 
Customer ABBA11-may-18445 
Customer ABBB11-may-1833688 
Customer ABBB25-may-18245 
Customer AC    No purchase
Customer AD    No purchase
Customer AD     
Customer AD     
Customer AE    No purchase
Customer AE     

 

I hope you can adjust the DAX so it only returns No Purchase once if there are multiple empty product groups under the same customer.

 

Regards,

Guido

Hi Guido,

 

I think you still consider the [Customer]. Please check out the formula below.

1. Add an index in the Query Editor due to all the blank columns are same.

2. New measure.

NEW =
VAR minIndex =
    CALCULATE (
        MIN ( Table1[Index] ),
        ALLEXCEPT ( Table1, Table1[Product group], Table1[Customer] )
    )
VAR lastestDate =
    CALCULATE (
        MAX ( Table1[date purchase] ),
        ALLEXCEPT ( Table1, Table1[Product group], Table1[Customer] )
    )
VAR PGHasPur =
    CALCULATETABLE (
        VALUES ( Table1[Product group] ),
        FILTER ( ALL ( 'Table1' ), Table1[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 ()
        )
    )

Identify_no_purchase_after_specific_date_or_no_purchase_at_all2

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft

 

Thank you very much again for your help. We are almost there 🙂

 

Becuase of the merged table it could happen that a product group appears multiple times. Sometimes there has been a purchase on a product group. However, because of the merged tables there could be a row where the same product group appears but is empty.

 

Try to explain in the data below (at the bottem A & B is added):

CustomerProduct group productdate purchaseAmountPriceNo regular purchase 
Customer AAAA11-may-1825  
Customer AAAB11-may-18528  
Customer ABBA11-may-18445  
Customer ABBB11-may-1833688  
Customer ABBB25-may-18245  
Customer AC    No purchase 
Customer AD    No purchase 
Customer AD      
Customer AD      
Customer AE    No purchase 
Customer AE      
Customer AA      
Customer AB      

 

Hope you can help me with this.

 

Regards,

Guido

Hi Guido,

 

Let's follow the example in the first post. What should the column be like below?

Customer Product group  product date purchase Amount Price No regular purchase
Customer A A AA 11-May-18 2 5  
Customer A A AB 11-May-18 5 28  
Customer A B BA 11-May-18 4 45  
Customer A B BB 11-May-18 33 688  
Customer A B BB 25-May-18 2 45  
Customer A C         No purchase
Customer A D         No purchase
Customer B A AA 21-Apr-18 2 68  
Customer B A AB 21-Apr-18 6 33  
Customer B A AB 4-May-18 4 78  
Customer B A AD 4-May-18 8 93  
Customer B B BA 4-May-18 4 54  
Customer B B BB 4-May-18 2 12  
Customer B C         No purchase
Customer B D DA 21-Dec-17 8 85  
Customer B D DB 11-Jan-18 6 43 No purchase
Customer C A         No purchase
Customer C B BA 6-Apr-18 4 93  
Customer C B BB 11-Apr-18 5 5  
Customer C C CA 24-May-16 6 72  
Customer C C CB 6-Oct-16 4 47  
Customer C C CC 21-Feb-17 8 32 No purchase
Customer A A          
Customer A A          
Customer A B          
Customer A B          
Customer A B          
Customer A C          
Customer A D          
Customer A E          
Customer A E          
Customer A E          
Customer A F          
Customer A F          
Customer A F        

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft

 

Were you able to find a solution?

 

Regards,

Guido

Hi Guido,

 

Did you try the formula again? It seems working. Please check out the demo in the attachment.

 

NEW = 
VAR minIndex =
    CALCULATE (
        MIN ( Table1[Index] ),
        ALLEXCEPT ( Table1, Table1[Product group], Table1[Customer] )
    )
VAR lastestDate =
    CALCULATE (
        MAX ( Table1[date purchase] ),
        ALLEXCEPT ( Table1, Table1[Product group], Table1[Customer] )
    )
VAR PGHasPur =
    CALCULATETABLE (
        VALUES ( Table1[Product group] ),
        FILTER ( ALL ( 'Table1' ), Table1[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 ()
        )
    )

Identify no purchase after specific date or no purchase at all.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft

 

I tried it again and it indeed it works better. 

After adapting it to my own data I discovered something else. 

 

I changed all dates of Customer C to 2016 

 

CustomerProduct groupproductdate purchaseAmountPriceNo regular purchase
Customer AAAA11-May-1825 
Customer AAAB11-May-18528 
Customer ABBA11-May-18445 
Customer ABBB11-May-1833688 
Customer ABBB25-May-18245 
Customer AC    No purchase
Customer AD    No purchase
Customer BAAA21-apr-18268 
Customer BAAB21-apr-18633 
Customer BAAB4-May-18478 
Customer BAAD4-May-18893 
Customer BBBA4-May-18454 
Customer BBBB4-May-18212 
Customer BC    No purchase
Customer BDDA21-dec-17885 
Customer BDDB11-jan-18643No purchase
Customer CA    No purchase
Customer CBBA6-apr-16493 
Customer CBBB11-apr-1655No Purchase
Customer CCCA3-Oct-16672 
Customer CCCB6-Oct-16447 
Customer CCCC11-Oct-16832No 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

 

The No purchase marked in red is not appearing in the data

 

Capture.PNG

 

Regards,

Guido

We need to make a few changes indeed. Try the formula below please.

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 ()
        )
    )

Best Regards,

Dale

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

Hi @Anonymous,

 

Did it work?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft,

 

Found a new challenge.

Due to merging tables quarterly the following situation might accure:

 

If the next quarter starts customer A has no purchase yet. However the MIN index identifies it as "no purchase".

See example below:

 

CustomerProduct groupproductdate purchaseAmountPriceNo regular purchase
Customer AA     
Customer AA     
Customer AAAA11-Aug-1825 
Customer AAAB11-Aug-18528 
Customer ABBA11-Aug-18445 
Customer ABBB11-Aug-1833688 
Customer ABBB25-Aug-18245 
Customer AC    No purchase
Customer AD    No purchase
Customer BAAA21-Jul-18268 
Customer BAAB21-Jul-18633 
Customer BAAB4-Aug-18478 
Customer BAAD4-Aug-18893 
Customer BBBA4-Aug-18454 
Customer BBBB4-Aug-18212 
Customer BC    No purchase
Customer BDDA21-dec-17885 
Customer BDDB11-jan-18643No purchase
Customer CA    No purchase
Customer CBBA6-apr-16493 
Customer CBBB11-apr-1655No Purchase
Customer CCCA3-Oct-16672 
Customer CCCB6-Oct-16447 
Customer CCCC11-Oct-16832No 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

 

Capture.PNG

Hope you can help me out.

 

regards,

Guido

Anonymous
Not applicable

Yes it worked! Thank you very much for your help.

Anonymous
Not applicable

@v-jiascu-msft

 

This it how it should look like:

Customer

Product group productdate purchaseAmountPriceNo regular purchase
Customer AAAA11-May-1825 
Customer AAAB11-May-18528 
Customer ABBA11-May-18445 
Customer ABBB11-May-1833688 
Customer ABBB25-May-18245 
Customer AC    No purchase
Customer AD    No purchase
Customer BAAA21-apr-18268 
Customer BAAB21-apr-18633 
Customer BAAB4-May-18478 
Customer BAAD4-May-18893 
Customer BBBA4-May-18454 
Customer BBBB4-May-18212 
Customer BC    No purchase
Customer BDDA21-dec-17885 
Customer BDDB11-jan-18643No purchase
Customer CA    No purchase
Customer CBBA6-apr-18493 
Customer CBBB11-apr-1855 
Customer CCCA24-May-16672 
Customer CCCB6-Oct-16447 
Customer CCCC21-feb-17832No 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

 

Regards,

Guido

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.