calculate count of distinct documents