September 29, 2021 at 2:31 am
Hello,
I need to change the % sales vs forecast column precision to be 2 decimal places instead of whole numbers. The confusing part is that I already have a format function and 'Po' as a '%" at the end, so I am trying to understand how I can make a % with two decimal points keeping this '%' sign in the field as well.
My formula:
FORMAT((f.TOTHIST - f.TOTFCST) / f.TOTFCST, 'P0') AS 'Sales VS FCST'
How I have now
If someone can help me how to adjust it and make it for example in the result as 48.88% instead of 49% that would be great!
Thank you!!
September 29, 2021 at 7:20 am
Format function does not change the calculation. It takes the results of the calculation and then modify the format. In your case all the columns in you expression are integer, so SQL Server returns an integer and then it formats it. If you want to have the results with decimal point, you need to cast one of your columns to another data type that supports decimal point, for example:
FORMAT((CAST f.TOTHIST AS MONEY) - f.TOTFCST) / f.TOTFCST, 'P0') AS 'Sales VS FCST'
Adi
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply