Clause in your UDF appian.dbo.udf_A
"WHERE ... datediff(day, [login_log].[dt_login], Convert([@date]))<=[@last_x_day"
eliminates all indexes and makes server scan whole table and return all rows, because it cannot predict result of the calculation.
Change it to
[login_log].[dt_login]>= datediff(day, - @last_x_day, Convert([@date]))
and make sure you have clustered index on column dt_login.
_____________
Code for TallyGenerator