Search code examples
u-sql

Calculate U-SQL Percentage


I am trying to calculate Deployment percentage. but my CASE statement is returning a whole number.

Example: Deployment = 133 Licensing = 930

Utilization should == 14%

However, returns 0

Here is the table schema for utilization:

,[Deployment (%)] float?

Here is how I calculate utilization:

        (summary.[Deployments] == 0 OR summary.[Licensing] == 0) ? 0 :
            (summary.[Deployments] / summary.[[Licensing]) AS [Deployment (%)]

Solution

  • Just needed to add (decimal) on the dividend

        (summary.[Deployments] == 0 OR summary.[Licensing] == 0) ? 0 :
            ((decimal)summary.[Deployments] / summary.[[Licensing]) AS [Deployment (%)]