Forum Discussion

leilei787's avatar
leilei787
Helper II
4 years ago
Solved

An odd count question

Hi All:

Happy Friday!

 

i have an odd question. here is my table below. i want to create a column that count how many times a customer show up

 

For example, customer A purchased 18 units on Jan 1st 2021, so that would be 1, and then customer A purchased again on 5/6/2021, so that count as 2 and Customer A showed up again in Sep, so that's 3. ( The result column is what i am looking for).....anyone could help me? thank you!!

 

Customer IDOrder DatePurchase QtyResult
A1/1/2021181
B1/15/202151
C3/4/2021121
D4/5/2021221
A5/6/2021162
B3/2/202152
C5/7/2021122
A9/4/202193
D8/1/202152
B10/8/202173
  • tamerj1's avatar
    tamerj1
    4 years ago

    Hi leilei787 
    Actually now it is much easier. Check out the updated file https://www.dropbox.com/t/gnQXLqmohiDQaOqd
    You just need two measures

     

    First Purchase Date = CALCULATE ( MIN (Data[Order Date] ), Data[Amount] > 0 )
    Last Purchase Date = CALCULATE ( MAX (Data[Order Date] ), Data[Amount] > 0 )

     

     The CALCULATE is only required to restrict the calculation on real sales transactions otherwise a simple MAX/MIN would be enough and the filter context will take care of the rest. You just need to place the Customer at the rows of the matrix visual and the Products ( either two or more) on the columns. Then place the two measures at the values, and that's it.

8 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    leilei787 Try:

    QtyResult Column = 
      VAR __Customer = [Customer ID]
      VAR __Date = [Order Date]
    RETURN
      COUNTROWS(FILTER('Table',[Customer ID] = __Customer && [Order Date] <= __Date))
    • leilei787's avatar
      leilei787
      Helper II

      thanks Greg! The formula works! However, i need to revise my question after deeper look at the project. so here is what i am looking for ( see below table).

       

      i have a list of customers with order date ( some order dates are the same because customer order different product). i am trying to identify a customer purchased a product the 1st time or 2nd time.

       

      For example, Customer A ordered both product X and Z the 1st time on 1/1/2021, and then Customer A purchased product X and Z again ( 2nd order) on 5/6/2021, and 3rd order on product X in Sep

       

      Order # can be number 1,2,3 instead of 1st, 2nd order

       

      Thank you again!

       

      Customer IDOrder DateProductPurchase QtyOrder #
      A1/1/2021x181st order
      A1/1/2021z51st order
      B1/15/2021x51st order
      C3/4/2021x121st order
      C3/4/2021y421st order
      D4/5/2021X221st order
      A5/6/2021x162nd order
      A5/6/2021Z72nd order
      B3/2/2021X52nd order
      C5/7/2021Y122nd order
      A9/4/2021X93rd order
      D8/1/2021X52nd order
      B10/8/2021X73rd order

       

       

    • leilei787's avatar
      leilei787
      Helper II

      Hi Tamerj1

       

      Appreciate for your solution. two additional question: how to setup a condition in your formula that rank the order only if amount >0....so if customer A placed a Demo order, because the value =$0, we do not count as an order....it has to be a real order with amount >$0

       

      Another question is...i want to create another column that identify first order and last order.....so in the example you provide, the 1st order would be first order.....the 3rd order would be the last order....but a customer would place many orders as time go on....it is easy to capture the first, but how to identify the last one? 

       

      thank you!!

       

      • tamerj1's avatar
        tamerj1
        Community Champion

        leilei787 

        Regarding your first question:

        Result = 
        IF (
            Data[Amount] > 0,
            RANKX ( 
                FILTER (
                    Data,
                    Data[Customer ID] = EARLIER ( Data[Customer ID] )
                ),
                Data[Order Date],,
                ASC,
                Dense
            )
        )

        Regarding yiu 2nd question. Please clarify. Do you want to flag the last sale and blank out othes?