I'm using sql and tableau to create a burn down chart. I wrote a sql query that does most of the calculation for me. I have a table structure that looks like this
| ld.cal_dt | ld.camp_name | ld.ld_cnt | dy_cmp.cal_dt | dy_cmp.camp_name | dy_comp.com_cnt | brndn |
|---|---|---|---|---|---|---|
| 2023-09-05 | Ex-000010 | 62 | NULL | NULL | NULL | NULL |
| 2023-09-06 | Ex-000010 | 0 | 2023-09-06 | Ex-000010 | 54 | -54 |
| 2023-09-08 | Ex-000010 | 0 | 2023-09-08 | Ex-000010 | 1 | -55 |
Below is what the relevant part of my query looks like
select lc.calendardate,
lc.campaign_name,
lc.loaded_count,
dcc.calendardate,
dcc.campaign_name,
dcc.completed_call_count,
sum(cast(lc.loaded_count as int) - cast(dcc.completed_call_count as int)) over(partition by lc.campaign_name order by lc.calendardate asc) as burn_down
from adjusted_loaded_count as lc
left join adjusted_daily_calls_completed as dcc on
lc.calendardate = dcc.calendardate and
lc.campaign_name = dcc.campaign_name
where lc.campaign_name is not null
I'm getting unexpected results in my burndown column. I expect the result to be 8 and then 7 instead of -54 and -55. Why aren't I actually getting the difference between the two numbers?
Three rows:
You want
You want to treat NULLs as zeros. Use
COALESCEfor this: