title: Get the Data for Each Month (till that month) for 12 months
body: <p>I have tried using the query to get the item counts(In + Out) for container, File-folder using the Detailed table.</p>
  
  <p>Eg.:
  Now the current month is July 2019.
  As per the snap shot table we will get the data as July 2019(&lt;=July 2019) and for June (&lt;= June 2019)..,</p>
  
  <p>But in detailed table, now our query gives counts only for July 2019, but we need the data till July 2019 (I,e.. &lt;=July 2019).</p>
  
  <p>Required:
  In the same manner we need the data for each month July 2019,June 2019.. to July 2018(12 months Trend).</p>
  
  <pre><code>SELECT CASE
         WHEN gdw.dim_strg_itm.rfid_stat_id = 1
            AND gdw.dim_strg_itm_tp.strg_itm_ctgry_dsc = 'CONTAINER'
            AND strg_itm_nw_stat_key IN (16004, 16000) THEN
          COUNT(strg_itm_nw_stat_key)
       END "CNT",
       CASE
         WHEN gdw.dim_strg_itm.rfid_stat_id = 2
            AND gdw.dim_strg_itm_tp.strg_itm_ctgry_dsc = 'CONTAINER'
            AND strg_itm_nw_stat_key IN (16004, 16000) THEN
          COUNT(strg_itm_nw_stat_key)
       END "NCNT",
       gdw.dim_dt.mo_yr_cd
  FROM   gdw.dim_dt dim_dt_fclty_srvc,
       gdw.dim_cust_acnt,
       gdw.dim_cust_dept,
       gdw.dim_strg_itm,
       gdw.dim_strg_itm_stat,
       gdw.dim_dt,
       gdw.fact_rim_itm_actvty_dtl,
       gdw.dim_strg_itm_tp
  WHERE  gdw.fact_rim_itm_actvty_dtl.actvty_dt_key || fact_rim_itm_actvty_dtl.dim_actvty_key || gdw.fact_rim_itm_actvty_dtl.actvty_tm_key =
       (SELECT MAX(actvty_dt_key || dim_actvty_key || actvty_tm_key)
        FROM   gdw.fact_rim_itm_actvty_dtl a1
        INNER  JOIN gdw.dim_dt dt
        ON     a1.actvty_dt_key = dt.dim_dt_key
        WHERE  gdw.fact_rim_itm_actvty_dtl.dim_strg_itm_key = a1.dim_strg_itm_key
        AND    gdw.fact_rim_itm_actvty_dtl.dim_cust_acnt_key = a1.dim_cust_acnt_key
        AND    gdw.fact_rim_itm_actvty_dtl.dim_cust_dept_key = a1.dim_cust_dept_key
        AND    a1.strg_itm_nw_stat_key &lt;&gt; -1
        AND    dt.clndr_dt &lt;= '02-FEB-2019')
  AND    (gdw.fact_rim_itm_actvty_dtl.actvty_dt_key = dim_dt_fclty_srvc.dim_dt_key)
  AND    (gdw.fact_rim_itm_actvty_dtl.dim_strg_itm_key = gdw.dim_strg_itm.dim_strg_itm_key)
  AND    (gdw.dim_cust_acnt.dim_cust_key = gdw.fact_rim_itm_actvty_dtl.dim_cust_acnt_key)
  AND    (gdw.fact_rim_itm_actvty_dtl.dim_cust_dept_key = gdw.dim_cust_dept.dim_cust_dept_key)
  AND    (gdw.fact_rim_itm_actvty_dtl.strg_itm_nw_stat_key = gdw.dim_strg_itm_stat.dim_strg_itm_stat_key)
  AND    (gdw.fact_rim_itm_actvty_dtl.actvty_dt_key = gdw.dim_dt.dim_dt_key)
  AND    (gdw.dim_strg_itm.strg_itm_tp_cd = gdw.dim_strg_itm_tp.strg_itm_tp_cd)
  AND    (gdw.dim_cust_acnt.cust_id IN '7y897451'
      --@Prompt('Account:','A','Customer\Customer Account\Level 1 Account Code',Multi,Free,Persistent,,User:0)
      AND (gdw.dim_cust_acnt.src_sys_cd = 'RSSQL' AND substr(cust_id, 1, 2) IN ('ON', 'RP', 'RE', 'RL', 'PR', 'PL', 'LC', 'LE', 'PT', 'RR')) AND
      gdw.dim_cust_acnt.src_sys_cd IN ('RSSQL'))
  GROUP  BY gdw.dim_strg_itm.rfid_stat_id,
          gdw.dim_strg_itm_tp.strg_itm_ctgry_dsc,
          strg_itm_nw_stat_key,
          gdw.dim_dt.mo_yr_cd
  ORDER  BY to_date(gdw.dim_dt.mo_yr_cd, 'Mon YYYY') DESC
  </code></pre>
  
  <p>For Example: january 2019 data (sum of all months data less than or equal to January 2019 ), similarly, for Feb 2019 (sum of data &lt;=Feb 2019). like this for 12 months.</p>