From the below query I am struggling to get the Failure Percentage as it is always coming as zero. Am I doing something wrong.
from n in calculateOrderStatus
group n by new { n.OrderDate.Date, n.OrderDate.Hour } into h
select new
{
Failed = h.Sum(n => n.Failed),
Success = h.Sum(n => n.Success),
FailurePercentage = (h.Sum(n => n.Failed) / h.Sum(n => n.Success)) * 100
}
You’re doing integer division, not floating point: therefore dividing Failed by Success will always give you zero if Failed < Success. Multiply Failed by 100 first, then divide by Success.
i.e.
FailurePercentage = 100 * h.Sum(n => n.Failed) / h.Sum(n => n.Success)