Stay organized with collections
Save and categorize content based on your preferences.
In certain dialects, including Postgres and Redshift, performing a calculation between integers (like dividing counts) will return an integer even if the result would be a decimal in normal math. For example, you might make measures like the following:
measure: sold_ratio {
type: number
sql: ${sold_count} / ${total_count} ;;
value_format: "0.00" # Number with exactly 2 decimals (1.23)
}
measure: sold_percent {
type: number
sql: 100 * ${sold_count} / ${count} ;;
value_format: "0.00"
}
However, when you run the measures in an Explore, the Sold Ratio column returns zero, and the Sold Percent column does not have its decimal places populated. This is not correct:
Inventory Items Sold Percent
Inventory Items Sold Ratio
Inventory Items Count
Inventory Items Sold Count
48.00
0
1,165,224
560,223
The solution: Cast your field as a floating-point number
If the calculation is multiplied by a non-integer, the values will cast as floats, and decimals will be returned as expected. You can multiply the numerator by a decimal number (like 1.0 or 100.0) to force SQL to return a decimal result:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-22 UTC."],[],[],null,["# Why are my fields with division showing up as 0?\n\nIn certain dialects, including Postgres and Redshift, performing a calculation between integers (like dividing counts) will return an integer even if the result would be a decimal in normal math. For example, you might make measures like the following: \n\n```\nmeasure: sold_ratio {\n type: number\n sql: ${sold_count} / ${total_count} ;;\n value_format: \"0.00\" # Number with exactly 2 decimals (1.23)\n}\nmeasure: sold_percent {\n type: number\n sql: 100 * ${sold_count} / ${count} ;;\n value_format: \"0.00\"\n}\n```\n\n\nHowever, when you run the measures in an Explore, the **Sold Ratio** column returns zero, and the **Sold Percent** column does not have its decimal places populated. This is not correct:\n\n\u003cbr /\u003e\n\n\nThe solution: Cast your field as a floating-point number\n--------------------------------------------------------\n\n\nIf the calculation is multiplied by a non-integer, the values will cast as floats, and decimals will be returned as expected. You can multiply the numerator by a decimal number (like 1.0 or 100.0) to force SQL to return a decimal result: \n\n```\nmeasure: sold_ratio {\n type: number\n sql: 1.0 * ${sold_count} / ${total_count};;\n value_format: \"0.00\"\n}\nmeasure: sold_percent {\n type: Number\n sql: 100.0 * ${sold_count} / ${count};;\n value_format: \"0.00\"\n}\n```\n\n\nThe resulting Explore **Data** table now displays the expected results:\n\n\n\u003cbr /\u003e"]]