KNOWLEDGE BASE

How to Fill in Leading Zeros to a String


Published: 21 Dec 2021
Last Modified Date: 23 Dec 2021

Question

How to fill in the leading zero to a string.

For example:
A       -> 000A
AB    -> 00AB
ABC -> 0ABC

Environment

  • Tableau Desktop 

Answer

1. Create a calculation field named "OriginalData(Edited)" to add a zeros string of  N digits to head of the original string. ( N = the final length of the string)
 Calculation formula: "0000"+STR([OriginalData])

2. Create a calculation field to trim the right N digits of  [OriginalData(Edited)]
 Calculation formula: RIGHT( [OriginalData(Edited)],4)


 
Did this article resolve the issue?