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
buttercream
Helper I
Helper I

Flag consecutive values based on multiple columns

Hi all,

 

Need your help.  I'm trying to flag customers that made multiple purchases in the same day.  The purchase ID must be within 3 numbers of each other.  So the same customer on the same day makes purchase ID 100, 103, and 104 should all be flagged as consecutive.  Below is a sample table and the consecitive column is what I'm trying to calculate.

 

CustomerDatePurchase IDConsecutive
A4/30/20251125No
B5/20/20251244No
C3/5/20251003Yes
C3/5/20251004Yes
C3/5/20251006Yes
D6/10/20251356No
D6/11/20251357No
E6/12/20251391No
E6/12/20251395No
1 ACCEPTED SOLUTION
MasonMA
Community Champion
Community Champion

Hi @buttercream 

 

Consider building a new Column in your table with below:

 

VAR ThisCustomer = Purchases[Customer]
VAR ThisDate = Purchases[Date]
VAR ThisID = Purchases[Purchase ID]
VAR OtherPurchases =
    FILTER (
        Purchases,
        Purchases[Customer] = ThisCustomer &&
        Purchases[Date] = ThisDate &&
        ABS ( Purchases[Purchase ID] - ThisID ) <= 3 &&
        Purchases[Purchase ID] <> ThisID
    )
RETURN
IF ( COUNTROWS ( OtherPurchases ) > 0, "Yes", "No" )
 
MasonMA_0-1753462402216.png

 

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=if(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Customer]=EARLIER(Data[Customer])))=1,"No",if(or(Data[Purchase ID]-CALCULATE(MAX(Data[Purchase ID]),FILTER(Data,Data[Customer]=EARLIER(Data[Customer])&&Data[Date]=EARLIER(Data[Date])&&Data[Purchase ID]<EARLIER(Data[Purchase ID])))<=3,and(CALCULATE(min(Data[Purchase ID]),FILTER(Data,Data[Customer]=EARLIER(Data[Customer])&&Data[Date]=EARLIER(Data[Date])&&Data[Purchase ID]>EARLIER(Data[Purchase ID])))-Data[Purchase ID]<=3,CALCULATE(min(Data[Purchase ID]),FILTER(Data,Data[Customer]=EARLIER(Data[Customer])&&Data[Date]=EARLIER(Data[Date])&&Data[Purchase ID]>EARLIER(Data[Purchase ID])))-Data[Purchase ID]>0)),"Yes","No"))

Hope this helps.

Ashish_Mathur_0-1753510070070.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
MasonMA
Community Champion
Community Champion

Hi @buttercream 

 

Consider building a new Column in your table with below:

 

VAR ThisCustomer = Purchases[Customer]
VAR ThisDate = Purchases[Date]
VAR ThisID = Purchases[Purchase ID]
VAR OtherPurchases =
    FILTER (
        Purchases,
        Purchases[Customer] = ThisCustomer &&
        Purchases[Date] = ThisDate &&
        ABS ( Purchases[Purchase ID] - ThisID ) <= 3 &&
        Purchases[Purchase ID] <> ThisID
    )
RETURN
IF ( COUNTROWS ( OtherPurchases ) > 0, "Yes", "No" )
 
MasonMA_0-1753462402216.png

 

Perfect.  Thank you !!!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors