Treemap color

Hi everyone,

I am new to looker and I am trying to create a RFM analyses, for this I need a treemap with the customer groups. In this treemap the tiles need to be a specific colour respective of the customer group label. (Red for lost customers, orange for normal customers, green for good customers,...).

However, when I create this treemap, I can specify a custom colour palette but this colours the values from biggest to smallest not per group label. Now my question is, how can I (conditionally) format these tiles in the respective colours?

Thanks in advance,
Kevin

image_2023-08-22_154338540.png

Solved Solved
0 1 627
1 ACCEPTED SOLUTION

Update:
I fixed it by adding a table calculation that "hard codes" the label names with an if-else structure to number them in the order that I want.  (ex. If lost customer then 1, else if hibernating then 2 , ....), Then just hide the column and sort by that column in the data view.
This solution works for me because the labels are static and won't change. I am not sure how you could do it dynamically, probably with different code.

Correct treemap:
Correct treemap and table calculationCorrect treemap and table calculation

Code for the table calculation:

if(${datadrivencx_rfm.rfm_label}="Lost Customers",1,
    if(${datadrivencx_rfm.rfm_label}="Customer hibernating",2,
        if(${datadrivencx_rfm.rfm_label}="Reel customer back in!",3,
            if(${datadrivencx_rfm.rfm_label}="Customer at risk",4,
                if(${datadrivencx_rfm.rfm_label}="Recent Prudent Customers",5,
                    if(${datadrivencx_rfm.rfm_label}="NaN",6,
                        if(${datadrivencx_rfm.rfm_label}="Recent Promising Customers",7,
                            if(${datadrivencx_rfm.rfm_label}="Potential Loyal Customers",8,
                                if(${datadrivencx_rfm.rfm_label}="Loyal Customers",9,
                                    if(${datadrivencx_rfm.rfm_label}="Loyal Whales",10,5))))))))))

Note: I put 5 by the else from the "Loyal Whales" because for some reason the "Recent Prudent Customers" where getting in that else. It is a quick and dirty fix but it works for now. 

Hope this helps/inspires someone else to get their solution!
Regards,
Kevin

View solution in original post

1 REPLY 1

Update:
I fixed it by adding a table calculation that "hard codes" the label names with an if-else structure to number them in the order that I want.  (ex. If lost customer then 1, else if hibernating then 2 , ....), Then just hide the column and sort by that column in the data view.
This solution works for me because the labels are static and won't change. I am not sure how you could do it dynamically, probably with different code.

Correct treemap:
Correct treemap and table calculationCorrect treemap and table calculation

Code for the table calculation:

if(${datadrivencx_rfm.rfm_label}="Lost Customers",1,
    if(${datadrivencx_rfm.rfm_label}="Customer hibernating",2,
        if(${datadrivencx_rfm.rfm_label}="Reel customer back in!",3,
            if(${datadrivencx_rfm.rfm_label}="Customer at risk",4,
                if(${datadrivencx_rfm.rfm_label}="Recent Prudent Customers",5,
                    if(${datadrivencx_rfm.rfm_label}="NaN",6,
                        if(${datadrivencx_rfm.rfm_label}="Recent Promising Customers",7,
                            if(${datadrivencx_rfm.rfm_label}="Potential Loyal Customers",8,
                                if(${datadrivencx_rfm.rfm_label}="Loyal Customers",9,
                                    if(${datadrivencx_rfm.rfm_label}="Loyal Whales",10,5))))))))))

Note: I put 5 by the else from the "Loyal Whales" because for some reason the "Recent Prudent Customers" where getting in that else. It is a quick and dirty fix but it works for now. 

Hope this helps/inspires someone else to get their solution!
Regards,
Kevin