Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Conditional Sum Data based on sequence.

$
0
0

I need to do some conditional summing in my SSRS report.

As of right now, it just sums up the values by common CASEID per FINISH,

but I need it to conditionally sum while the IDs are consecutive,

once they are not, the sum is displayed and the next ID is counted.

Even if a previous ID comes back, it must start a new line and a new sum.

This is my raw data in SQL

RTYPE CASEID QTY BLOCK FINISH ---------------------------------- CASE 1058769 1 5001 4686 CASE 1023964 1 5001 4686 CASE 1058769 1 5001 4686 CASE 1043742 1 5001 4686 CASE 1043742 1 5001 4686 CASE 1043742 1 5001 4686 CASE 1058769 7 5001 4686 CASE 1043742 1 5001 4686 CASE 1043742 1 5001 4686 CASE 1043742 1 5001 4686 CASE 1043742 1 5001 4686 CASE 1043742 7 5001 4686

This is the data I'm getting in my SSRS report

RTYPE   CASEID  QTY BLOCK   FINISH
----------------------------------
CASE    1058769 9   5001    4686
CASE    1023964 1   5001    4686
CASE    1043742 14  5001    4686

But this is the data I am trying to display

RTYPE   CASEID  QTY BLOCK   FINISH
----------------------------------
CASE    1058769 1   5001    4686
CASE    1023964 1   5001    4686
CASE    1058769 1   5001    4686
CASE    1043742 3   5001    4686
CASE    1058769 7   5001    4686
CASE    1043742 11  5001    4686

I've truncated the code above to easier readability but our sql statement in SSRS (which pulls from two different views in Oracle) is a little more verbose, but it builds the report using this query:

SELECT RTYPE,
  min(SORTKEY1) sortkey1,
  COORDINATED_BLOCK,
  FINISH,
  case when (RTYPE = 'CASE' OR CASEID LIKE '%PULL%') THEN CASEID
 ELSE DWR_CONFIG || '-' || PULLTYPE END AS CASEID,
  sum(QTY) Qty
FROM
  (SELECT RTYPE,
    COORDINATED_BLOCK,
    CASEID,
    CASETYPE,
    DWR_CONFIG, PULLTYPE, 
    FINISH,
    MIN(ID)  AS SORTKEY1,
    SUM(QTY) AS QTY
  FROM CASE_FRONT_SUMMARY_TEST
  WHERE MATERIAL_DESCRIPTION NOT LIKE '%HANGER%'
  AND RTYPE = 'CASE'
  GROUP BY RTYPE,
    COORDINATED_BLOCK,
    CASEID,
    CASETYPE,
    DWR_CONFIG, PULLTYPE,
    FINISH
  ) XXX
  group by rtype, coordinated_block, finish, 
        case when (RTYPE = 'CASE' OR CASEID LIKE '%PULL%') THEN CASEID
 ELSE DWR_CONFIG || '-' || PULLTYPE END
order by 3, 2, 4, 5

Is something like this even possible in SSRS or SQL? We are stumped over here.




Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>