This is a tricky solution, we check to see if valid (ie equals P) then Concatenate string and wehen NULL use an empty string. And we replace any 'A' comin in to empty string.
Suppose you have 5 Presents, you get PPPPP, now you take length of the this, you get how many P's as they all are single character.
SELECT
Mon
, year
, Emp_Id
, LEN(REPLACE(COALESCE(D1, '') + COALESCE(D2, '') + COALESCE(D3, '') +... +COALESCE(D30, ''),'A',''))
FROM yourTable
Thanks,
Kuthuparakkal