Quantcast
Channel: SQLServerCentral » Reporting Services » Reporting Services » Latest topics
Viewing all articles
Browse latest Browse all 2791

distinct sum for an expression

$
0
0
I have a report that displays the sum of a particular field like this:[code="sql"]=SUM(iif(Fields!isFinished.Value = 1, Fields!isFinished.Value, 0))[/code]Sometimes it works, but sometimes I get the wrong totals because it's counting one particular field more than once because that field happens to contain the same Id more than once.Here is some sample data that shows the results that I'm dealing with:[code="sql"] SELECT 'Jimmy' AS Person,'12345' As weaponId,1 AS isFinished UNION ALL SELECT 'Jimmy','12345',0 UNION ALL SELECT 'Jimmy','789',1 UNION ALL SELECT 'Alex','12345',1 UNION ALL SELECT 'Alex','12345',1 UNION ALL SELECT 'Alex','12345',0 UNION ALL SELECT 'Kate','53274',1 UNION ALL SELECT 'Kate','789',1 UNION ALL SELECT 'Kate','83752',1;[/code]I only need the report to SUM the row on each questionId once. So a sample report would just have totals like this:only count each weapondId ONCETotals:[b]Jimmy = 2Alex = 1Kate = 3[/b]After some googling, I tried playing around with ROW_NUMBER and RANK in my SQL query, but that didn't solve my problem.Is there a way to do this in SSRS or even the SQL?Thanks!

Viewing all articles
Browse latest Browse all 2791

Trending Articles