Expand my Community achievements bar.

Join us for the next Community Q&A Coffee Break on Tuesday April 23, 2024 with Eric Matisoff, Principal Evangelist, Analytics & Data Science, who will join us to discuss all the big news and announcements from Summit 2024!

Number stored as text? - How to convert from a prop/eVar to a metric

Avatar

Community Advisor

7/14/22

We all regret decisions in life; in Adobe Analytics we may regret storing a number in an eVar or prop! This is because unlike custom events, you can't perform numerical calculations (such as summing or averaging) on props or eVars.
Obviously, you can make changes to your implementation to capture these values in a custom event going forward. However, what can be done about your historical data? Fortunately, using a combination of Classifications and Calculated Metrics this can be taken care of.

Method

To explain the approach, I'm going to use the example of converting from a three-digit number stored in a prop, to a metric. However, this method can be extended to cope with any number of digits and decimal places as well.

Step1: Create classifications

We are going to use classifications to split our number up into separate classifications, one classification for each individual digit in the number.
In this example we are dealing with a three-digit number so we will need three classifications: one for the units, one for the tens, and one for the hundreds.

Andrew_Wathen__0-1657299258962.png

Step 2: Populate the classifications

We need to use the Classification Rule Builder to dynamically split the digits of the number into the three classifications.

For example, if the value in the prop was "874" then we would want the:

  • "units" classification to be dynamically set to "4"
  • "tens" classification to be dynamically set to "7"
  • "hundreds" classification to be dynamically set to "8"

To do this we require some RegEx:

  • (^\d*)(\d$) returns the ‘units’ in match group $2
  • (^\d*)(\d)(\d$) returns the ‘tens’ in match group $2
  •  (^\d*)(\d)(\d)(\d$) returns the ‘hundreds’ in match group $2 

Andrew_Wathen__0-1657814029923.png

Step 3: Build the calculated metric

The final step is to build a calculated metric to convert these classifications to numbers using the "if" function and static numbers.  For example...

  • If "unit" equals "1" then static number 1, plus
  • If "unit" equals "2" then static number 2, plus
  • If "unit" equals "3" then static number 3, plus
  • ...etc. (all the way to 9), plus
  • If "tens" equals "1" then static number 10, plus
  • If "tens" equals "2" then static number 20, plus
  • If "tens" equals "3" then static number 30, plus
  • ...etc. (all the way to 90), plus
  • If "hundreds" equals "1" then static number 100, plus
  • If "hundreds" equals "2" then static number 200, plus
  • If "hundreds" equals "3" then static number 300, plus
  • ...etc. (all the way to 900)

Screen shot of how this looks in the Calculated Metric Builder:

Andrew_Wathen__1-1657815519041.png

...and that's it! We now have a calculated metric for the values in the prop that we can perform numerical calculations on.

In conclusion, this method does take a bit of set up, but if you're stuck with a a number in a prop or eVar this may just save the day!

4 Comments

Avatar

Community Advisor

7/18/22

This is a good description of a workaround. 

 

However I do miss the numeric 2 classification.

Avatar

Community Advisor

8/16/22

Glad we don't have to do this anymore in Customer Journey Analytics!