Need a little help converting this:
to...
where
Percentage is simply N / (D - E)
I did read this, this and few other posts.
Is there a simpler way to add compute to the transposed columns !?
Just another option
Select *
,Pct = ( IsNull([N],0)+0.0) / NullIf((IsNull([D],0)-IsNull([E],0) ),0)
From YourTable A
Pivot ( sum(Users) for Marker in ([D],[E],[N]) ) pvt
EDIT - Corrected for NULLS
I would use a subquery or CTE:
select d.*,
n * 1.0 / nullif(d - e, 0) as ratio
from (select date,
sum(case when market = 'D' then users else 0 end) as d,
sum(case when market = 'E' then users else 0 end) as e,
sum(case when market = 'N' then users else 0 end) as n
from t
group by date
) d;