Hi @Bone_12 ,
We recommend that you post CREATE TABLE statements for your tables together with INSERT statements with sample data, enough to illustrate all angles of the problem. We also need to see the expected result of the sample.
over (partition by mort_no , due_date, splits, loc )
You used four columns in your partition part, but the value of splits and loc for Mort_No 3 were totally different.
So you will always receive the duplicated output (Mort_No 3).
You could have a try to filter out the third row firstly and do the aggregation like below:
;with cte as (
select * from yourtable
except
select * from yourtable
where Mort_no in (select Mort_no from yourtable where splits<>0) and splits=0)
select *,
case splits when 0
then sum(value) over (partition by mort_no , due_date, splits, loc )
else
sum(value) over (partition by mort_no ,due_date, splits , loc) * (splits / 100)
end as total_bal
from cte
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.