Overview
A dataset of products uses inconsistent labeling for the category codes. For example, electrical products have multiple code variations, such as ELEC, ELC, and elc. To standardize the codes, the Replace function is used to correct all inconsistent category codes for both electrical and furniture products.
Open the Data load editor and add the load script below to a new tab.
The load script contains:
Load script
Example:
Load * inline [
ProductID, CategoryCode
1, ELEC
2, ELC
3, FURN
4, FRN
5, ELEC
6, ELC
7, elc
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
Create the following calculated dimension:
-
=Replace(Replace(Upper(CategoryCode), 'ELC', 'ELEC'),'FRN', 'FURN'), to replace any instances of ELC with ELEC and any instance of FRN with FURN.
Results table
ProductID |
CategoryCode |
Replace(Replace(Upper(CategoryCode), 'ELC', 'ELEC'),'FRN', 'FURN') |
1 |
ELEC |
ELEC |
2 |
ELC |
ELEC |
3 |
FURN |
FURN |
4 |
FRN |
FURN |
5 |
ELEC |
ELEC |
6 |
ELC |
ELEC |
7 |
elc |
ELEC |
The output of the Replace function has replaced any instances of ELC with ELEC, and FRN with FURN. Note that the code elc was also replaced. Although the Replace function is case-sensitive, the dimension formula uses the Upper function to conform the case of all CategoryCodes before replacing the string. This effectively renders the string replacement case-insensitive.