The code I currently have shows me the current value for everyday and gives the running total.
select t.lgl_entity_nm, d.date_key, 
count(distinct s.site_key) AS Dis, 
SUM(Dis) over (partition by t.lgl_entity_nm order by d.date_key ASC rows unbounded preceding) RunningTotal
from site_v s
join touchpoint_v t
on s.site_key = t.site_key
join omni_promo_varnt_fact_v o
on o.touchpoint_key = t.touchpoint_key
join date_v d
on d.date_key = o.date_key
where d.date_key between 20190901 and 20190931
and t.lgl_entity_nbr = 1
and tot_selected_qty > 0
and event_typ_cd in ('IS-SPRINT-T', 'IS-PRINT-T')
group by 1,2
Giving me this output:
lgl_entity_nm   date_key    dis runningtotal
Ahold USA      20190901     729     729
Ahold USA      20190902     733     1462
If you look at the date its set between a certain time period. What I want achieve is that it shows me the current date or any set date value and past 30 days total in a single row. Suppose the date is 2019-09-30:
lgl_entity_nm   date_key(current date)  dis    total (past30 days)
Ahold USA       20190930                739     21953
Can this be achieved? If so how?