Я бы предложил что-то вроде этого:
with t1 as (
select distinct b.user, v.dte
from [Customerbase].[dbo].[Base] b join
(values (convert(date), date1), . . . -- list dates here
) v.dte
on b.date between dateadd(day -29, v.date) and v.dte
)
select t1.dte, sum(cast([bal] as decimal(16, 4))) as sum,
avg(cast([bal] as decimal(16, 4))) as avg
from t1 join
[reg].[dbo].[dailyfile] df
on t1.user = dt.user and
df.[date] = t1.dte
group by t1.dte;