I'm not following the requirements 100%, but I think that the following will help:
You can override filters with LoD calculations. They allow you to specify the grain of your data.
Here is some more information on them: Overview: Level of Detail Expressions
If you need to filter inside of a calculation, you can do that inside of the aggregation functions, for example:
SUM(IF [MyField] = 'A' THEN [MyValue] END)
Hope this helps!