Hello Ravi,
What is the fuctionality of Report_Sum, Is it taking sum of defined measures in report? If so you can use below based on your SQL Code
=Sum(If Level1='R' then 'Total R' Else If Level1 InList ("Sales";"other sales") Then Total cost of Sales Else Level2) In Report
I am assuming that Total R, Total Cost of Sales and Level2 are measure objects.
Similarly you can make use of Average here In Report is that keyword that is taking you entire reports data into consideration.
Regards
Niraj