I want to generate a cross tab report which summary field value is outcome of SUM(Field) / DISTINCTCOUNT(Field). The current one giving correct result for single day but value change if day increases.
Even tried the data filtration in stored procedure but script processing time is too long i.e, taking more than 8 mins to process required data from 39k records.
Data for one day: Multiple records for one user accessing same or more file(TopicId) more than one time. Duration in each row. So the requirement is to find Average time based on SUM(Duration) / DISTINCTCOUNT(TopicId).
Report Formule:
NullTest
==========
If IsNull({UserActivityLog.To
picId}) then 0 else 1
DistinctCount
===========
If Sum({@NullTest}) >0 then DistinctCount({UserActivit
yLog.Topic
Id})-1 else
DistinctCount({UserActivit
yLog.Topic
Id})
AverageTime (in Minute)
====================
({UserActivityLog.Duration
}/{@Distin
ctCount})/
60
Realised that SUM(Duration) need in formula and tried but not getting exact result.
Following script tried instead of formulae in report. Report coming correct but the query execution time is too much.
SELECT UAL.UserName, UAL.CreatedDate,
Duration = (SELECT (Sum(Duration) / COUNT(DISTINCT TopicId))/60
FROM UserActivityLog
WHERE SiteId = UAL.SiteId AND UserId = UAL.UserId AND
(CONVERT(VARCHAR(20), CreatedDate,101) = CONVERT(VARCHAR(20), UAL.CreatedDate,101)))
FROM dbo.UserActivityLog UAL
Any chance to optimised this query. The table having one clustered index and non-clustered indexes for required columns.
Please help me out of this. Im new to cross tab report and its very urgent.