Lift a chestnut! Tableau Tips (120): To use R to realize RFM customer value analysis

published: 2021-06-07

Regarding RFM analysis, we have shared the implementation method of complete use of computing fields: the RFM model is used to analyze customer value, as shown below.

After the post is sent, there is a data powder consultation that I like to explore: Is there a more convenient way to implement RFM in Tableau? For example, R.

Indeed, we can also use R to implement RFM analysis. Today, learn together!

The Tableau tricks that "lift a chestnut" and Ada want to share it with R to use R to use R to achieve RFM customer value analysis.

For your convenience, we use the Sample-SuperStore data source. After mastering the method, data powder can try to use other data sources.

Specific steps are as follows:

Step1: Install R and start Rserve

First, download R and complete the installation, then install the Rserve package and start the Rserve.

install.packages(“Rserve”)  

library(Rserve)     

Rserve()

Step2: Tableau Desktop connection Rserve

Open the Tableau Desktop connection R and enter the server and port number. Test the connection to click the OK button.

Step3: Create a calculation field

Next, create two calculation fields, Result, and RFM. Returns RFM Results with R's Function in the Calculating field: R Last purchase time, F purchase, M purchase total amount.

l  The Result calculation field is as follows:

SCRIPT_STR(’

r=ifelse(.arg1>mean(.arg1),2,1);

f=ifelse(.arg2>mean(.arg2),2,1);

m=ifelse(.arg3>mean(.arg3),2,1);

a<-paste(r,f,m,sep="-")

',

min(DATEDIFF(‘day’,[Order Date],now())),

avg({ FIXED [Customer ID]:COUNTD([Order ID])}),

sum([Sales])

)

l  The RFM calculation field is as follows:

IF [Result] = '2-2-2' Ten 'High Value Customer'

Elseif [Result] = '1-2-2' Ten 'focusing keeping customers'

Elseif [Result] = '2-1-2' TEN 'Key Development Customer'

Elseif [Result] = '1-1-2' TEN 'Key Return Customer'

Elseif [Result] = '2-2-1' TEN 'Key Protection Customer'

Elseif [Result] = '1-2-1' TEN 'General Protection Customer'

Elseif [Result] = '2-1-1' Ten 'General Development Customer'

Elseif [Result] = '1-1-1' TEN 'Potential Customer'

END

 

Step4: Create a chart

Drag and drop the calculation field "RFM" in the "color" of the line, filter, and tag card; drag the metric "Profit" to the "size" of the tag card; will measure "Sales" and the dimension "Customer ID" Drag and drop to the "label" of the tag card.

In this way, we use R to complete a RFM tree graph customer value analysis.

 

This issue of Tableau skills, have you get? Try it quickly!