Forum Discussion

Andrew_na_lang's avatar
3 years ago

CUSTOMER SEGMENTATION AGAINST ORDER RANKING

Hi Team,

I have two tables - Customers and Orders. These tables are connected via the customer_id via a one-to-many relationship. 
I created a calculated column in my customer's table named Redeemer_Status where customers are segmented into two - REDEEMER1 and REDEEMER2. 

Redeemer_Status =
VAR _CustomerID = customers[id]
VAR _HC_1 = CALCULATE(MAX(orders[with HC]), FILTER(orders, orders[_Order Ranking] = 1 && orders[customer_id] = _CustomerID))
VAR _SignUpOrigin_1 = CALCULATE(MAX(orders[SignUp_Origin]), FILTER(orders, orders[_Order Ranking] = 1 && orders[customer_id] = _CustomerID))
VAR _HC_2 = CALCULATE(MAX(orders[with HC]), FILTER(orders, orders[_Order Ranking] = 2 && orders[customer_id] = _CustomerID))
VAR _SignUpOrigin_2 = CALCULATE(MAX(orders[SignUp_Origin]), FILTER(orders, orders[_Order Ranking] = 2 && orders[customer_id] = _CustomerID))

RETURN
IF(
    _HC_1 = 1 && (_SignUpOrigin_1 = "WHATSAPP_BOT" || _SignUpOrigin_1 = "MOBILE_APP"),
    "REDEEMER1",
    IF(
        _HC_1 = 0 && (_SignUpOrigin_1 = "WHATSAPP_BOT" || _SignUpOrigin_1 = "MOBILE_APP") && _HC_2 = 0 && (_SignUpOrigin_2 = "WHATSAPP_BOT" || _SignUpOrigin_2 = "MOBILE_APP"),
        "NON-REDEEMER",
        IF(
            _HC_2 = 1 && (_SignUpOrigin_2 = "WHATSAPP_BOT" || _SignUpOrigin_2 = "MOBILE_APP") && _HC_1 = 0 && (_SignUpOrigin_1 = "WHATSAPP_BOT" || _SignUpOrigin_1 = "MOBILE_APP"),
            "REDEEMER2",
            BLANK()
        )
    )
)


I created a stacked column chart where the column _Order Ranking in my orders table serves as the x-axis and customer_id (Unique) in my Y-axis. I then use the Redeemer_Status column as the legend but filtered it with only the REDEEMER1 and REDEEMER2. 

I am so confused as to why there are REDEEMER2 that show up in the order ranking 1 instead they should only start to appear in the 2nd order onwards. 


In this graph, there should be no REDEEMER2 in the column for order rank 1. The 141 REDEEMER2 is incorrect and should not appear there. 
What did I do wrong? 




7 Replies