I have a situation where i have to calculate percentage of two values for example
IEnumerable<RenewalModel> result =
from r in renewalLists
group r by r.CityID into grpCity
select new RenewalModel
{
CityID = grpCity.Key,
City = (from g in grpCity where g.CityID == grpCity.Key select g.City).First().Trim(),
PotentialRenewalCount = (from g in grpCity where g.CityID == grpCity.Key select g.PotentialRenewalCount).Sum(),
PotentialRenewalSQRT = (from g in grpCity where g.CityID == grpCity.Key select g.PotentialRenewalSQRT).Sum(),
desiredCalucation= (PotentialRenewalCount/PotentialRenewalCount)*100,
RENEWALCOUNT = (from g in grpCity where g.CityID == grpCity.Key select g.RENEWALCOUNT).Sum(),
RENEWALSQRT = (from g in grpCity where g.CityID == grpCity.Key select g.RENEWALSQRT).Sum()
};
and my calculation should be like this
(PotentialRenewalCount/PotentialRenewalCount)*100
as i have described it inside the select statement.
i even tried this query but i get the 0 as result
IEnumerable<RenewalModel> result =
(from r in renewalLists
group r by r.CityID into grpCity
select new RenewalModel
{
CityID = grpCity.Key,
City = (from g in grpCity where g.CityID == grpCity.Key select g.City).First().Trim(),
PotentialRenewalCount = (from g in grpCity where g.CityID == grpCity.Key select g.PotentialRenewalCount).Sum(),
PotentialRenewalSQRT = (from g in grpCity where g.CityID == grpCity.Key select g.PotentialRenewalSQRT).Sum(),
RENEWALCOUNT = (from g in grpCity where g.CityID == grpCity.Key select g.RENEWALCOUNT).Sum(),
RENEWALSQRT = (from g in grpCity where g.CityID == grpCity.Key select g.RENEWALSQRT).Sum()
}).select(r => new RenewalModel
{
desiredCalucation = (r.PotentialRenewalCount / r.PotentialRenewalCount) * 100,
CityID = r.CityID,
City = r.City,
PotentialRenewalCount = r.PotentialRenewalCount,
PotentialRenewalSQRT = r.PotentialRenewalSQRT,
RENEWALCOUNT = r.RENEWALCOUNT,
RENEWALSQRT = r.RENEWALSQRT
});
for some reason or another desiredCalucation variable is giving me 0 as result.
any help is appreciated. Thank you