Regarding the performance difference, most probably there's an index on the [projectid] and the COALESCE function prevents the query using the index. How is the RLS set in your case, does it has anything to do with the [projectid]?
As far as I know, there's no way to influence the dynamic SQL generation.
Based on my research, the dynamic query would always use COALESCE regardless of the "Allow unrestricted measures" option. As to DirectQuery mode in Power BI Embeded, then I think you're using a Azure database? So far I can't think of any workaround to bypass the performance issue. Maybe you can try to upgrade Azure database to a higher service tier or use import mode instead.
Please submit an feedback on Power BI Ideas. Meanwhile I will report this internally and post back if there comes any update.
We are facing the same issue. Is there any way to ged rid of the COALESCE in the dynamic query? We found that COALESCE is not used when the report is opened from Power BI desktop and its used only through Power BI Embedded. Any help regarding this is highly appreciated.