Forum Discussion

VP1310's avatar
VP1310
Frequent Visitor
3 years ago
Solved

Flag rows based on conditions

Hi Everyone,

I have a set of data as shown below,

CustomerInvoicedateEvent
A1/8/2023Trial
A4/8/2023Purchase
B1/8/2023Purchase
B3/8/2023Exchange
B4/8/2023Demo
C1/8/2023Purchase
C2/8/2023Exchange
C3/8/2023Trial
D1/8/2023Trial
D2/8/2023Purchase
D3/8/2023Exchange
D4/8/2023Purchase
E1/8/2023Demo
E4/8/2023Purchase

 

I need to create a new column say "IncludeFlag". This column should contain a flag based on the criterias as given below.

1) If the Customer's first Event is Trial or Demo then "1" should be flagged to every row of the customer.

2) "0" to be flagged incase the Event is not Trial or Demo or if the first event is not Trial or Demo.

Below is the desired output.

 

CustomerInvoicedateEventIncludeFlag
A1/8/2023Trial1
A4/8/2023Purchase1
B1/8/2023Purchase0
B3/8/2023Exchange0
B4/8/2023Demo0
C1/8/2023Purchase0
C2/8/2023Exchange0
C3/8/2023Trial0
D1/8/2023Trial1
D2/8/2023Purchase1
D3/8/2023Exchange1
D4/8/2023Purchase1
E1/8/2023Demo1
E4/8/2023Purchase1

 

Please suggest a way in which, I can achieve this.

 

Thank you and Regards

 

 

  • pls try this

     

     

    Flag = 
    VAR _t1 = [Customer]
    VAR _MinDate = MINX(FILTER(ALL('Table'),'Table'[Customer]=_t1),[Invoicedate])
    VAR _tbl = FILTER(ALL('Table'),'Table'[Customer]=_t1&&'Table'[Event]="Trial"&&[Invoicedate]=_MinDate)
    RETURN
    COUNTROWS(_tbl)

     

     

    If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

     

4 Replies

  • pls try this

     

     

    Flag = 
    VAR _t1 = [Customer]
    VAR _MinDate = MINX(FILTER(ALL('Table'),'Table'[Customer]=_t1),[Invoicedate])
    VAR _tbl = FILTER(ALL('Table'),'Table'[Customer]=_t1&&'Table'[Event]="Trial"&&[Invoicedate]=_MinDate)
    RETURN
    COUNTROWS(_tbl)

     

     

    If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

     

    • VP1310's avatar
      VP1310
      Frequent Visitor

      Thanks a lot, works as per my requirement.