Creating base query for the report