Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Help with solution for calculation based previous order

Hi!   I really hope someone has a quick and good solution for my issue.  What I need to do is to calculate how many order_type "order" that are generated after the customer placed the order_type "...
  • DataInsights's avatar
    DataInsights
    5 years ago

    Anonymous,

     

    Try this. I revised the logic to work at both the total level and the year/month level.

     

    Count of Order = 
    SUMX (
        ALL ( Customer ),
        VAR vCustomer = Customer[customer_key]
        VAR vHTOrderRow =
            FILTER (
                ALL ( Sales ),
                Sales[customer_key] = vCustomer
                    && Sales[order_type] = "ht_order"
            )
        VAR vHTOrderDate =
            MAXX ( vHTOrderRow, Sales[date_key] )
        VAR vCountOrderRows =
            CALCULATE (
                COUNTROWS ( Sales ),
                Sales[customer_key] = vCustomer,
                Sales[order_type] = "order",
                Sales[date_key] <= vHTOrderDate + 30
            )
        RETURN
            vCountOrderRows
    )