KNOWLEDGE BASE

Converting an Integer to Binary


Published: 16 Mar 2018
Last Modified Date: 16 Mar 2018

Question

How to convert an integer to binary in Tableau Desktop.

Environment

Tableau Desktop

Answer

Create a calculated field. The following calculation was used to convert SUM([Quantity]) to a binary value and can be reviewed in the attached packaged workbook:
str(int((SUM([Quantity])/2^11))%2)+

str(int((SUM([Quantity])/2^10))%2)+

str(int((SUM([Quantity])/2^9))%2)+

str(int((SUM([Quantity])/2^8))%2)+

str(int((SUM([Quantity])/2^7))%2)+

str(int((SUM([Quantity])/2^6))%2)+

str(int((SUM([Quantity])/2^5))%2)+

str(int((SUM([Quantity])/2^4))%2)+

str(int((SUM([Quantity])/2^3))%2)+

str(int((SUM([Quantity])/2^2))%2)+

str(int((SUM([Quantity])/2^1))%2)+

str(int((SUM([Quantity])/2^0))%2)

The above equation will convert an integer up to 2^11 (2048). For up to ~1 million, the above would have to be modified to include lines at the top for 2^20 down to 2^12.
Did this article resolve the issue?