Skip to Content
Former Member
Jan 20, 2014 at 04:29 AM

Get previous stock reading


hello all,

I have a requirement in webi report where I have a object as "Stock reading". I need a column which should be "Previous Stock reading".

I have prompts as : Site ID(mandatory), Sale date(date from and date to;mandatory) and Station number(Optional).

So in the webi report I have a section on Station Number. I need the previous stock reading based on the selected site Id and the Station number per section. If station number is 1234 so the previous stock reading should show up the value for the most recent one before 1234 and before the selected date range. so if in prompt I have selected date range as 9th dec 2013 to 19th jan,2014 and the data for Staion number 1234 is showing up for date range 9th dec to 31st dec and there is a Station Number 1233 for date 8th dec so the prevous stock reading for station no.1234 should show up that value i.e. the most recent one(1233 for date 8th dec.)if thats blank it should show up the value before that and if there is no station no. at all then it should show that blank.

below is a .net query that actually shows how to get previous stock reading. How do I implement it in the report?

public static decimal? GetPreviousDayStockReading(int productGroupID, DateTime closedate, string SITE_ID)


using (XYZEntities context = new XYZEntities(BaseBL.BLLConnection()))


var getPreviousProductStock = from s in context.SITE_SALES_SUMMARY

join pgs in context.PRODUCT_GROUP_SALES_SUMMARY on


where s.SITE_ID == SITE_ID &&

pgs.MASTER_PRODUCT_GROUP_ID == productGroupID &&

EntityFunctions.TruncateTime(s.CLOSE_TIME) <= EntityFunctions.TruncateTime(EntityFunctions.AddDays(closedate, -1))

select new { s, pgs };

if (getPreviousProductStock != null && getPreviousProductStock.ToList().Count > 0)


decimal? stockReading = getPreviousProductStock.OrderByDescending(i => i.s.CLOSE_TIME).FirstOrDefault().pgs.STOCK_READING;

return Math.Round(stockReading.HasValue ? stockReading.Value : 0, 2, MidpointRounding.AwayFromZero);




return null;