If you are using a slicer to filter, this blog shows how to use cube functions- https://powerpivotpro.com/2012/11/be...-in-a-formula/

If not, I would think that you need only use the VisibleItemsList property of the relevant pivot field, which only works with OLAP pivot tables.