Search code examples
powerbidax

Needing to ignore filter on a visual when calculating percentage onto another visual


this seems like it should be a simple task on the surface but I can't get my head wrapped around this one.

I have a visual bar chart (Chart A) showing the total number of prescriptions sent to various pharmacies. On another bar chart visual (Chart B) I show the individual providers and their percentage of the total prescriptions sent to each of those pharmacies.

The way it behaves now, which is expected out of the gate is if I select say, Pharmacy C from the Chart A, then in Chart B will show each provider and their percentage share of prescription sent to Pharmacy C. For example, if Pharmacy C received 1000 total scripts and provider A sent 250 of them, their respective percentage would be 25%. Makes sense.

However, I have received a request to not show the providers percentage share of the selected Pharmacy, but instead the percentage of their total scripts (to all pharmacies) that are sent to the selected pharmacy, in this case Pharmacy C. So for this same example, the provider still sent 250 scripts to Pharmacy C, but they want to know what percentage that is of their total scripts sent to any Pharmacy. So, if Provider sent 2000 total scripts to all pharmacies and sent the 250 to Pharmacy C, it would then show that 12.5% of their total scripts were sent to Pharmacy C.

What I have been trying is creating a measure to do this calculation using the total number of scripts written to all pharmacies per provider, however anytime I select a specific pharmacy from the Chart A, it still filters the providers total script count just that selected pharmacy. For the calculation of total scripts I want it to ignore the selected pharmacy and count all scripts sent by the provider, regardless of pharmacy. i have attempted using the various CALCULATE and filter functions but I can't seem to figure this one out.

I apologize, this is the best way that I can explain it.


Solution

  • Look at using REMOVEFILTERS.

    Suggest creating these three measures - note for the second one, you need to remove "filter context" on Pharmacy not Provider:

    Prescription Count =
      DISTINCTCOUNT('Rx Data'[PrescriptionID])
    
    Total Provider Prescriptions = 
      CALCULATE(
        [Prescription Count],
        REMOVEFILTERS('Rx Data'[Pharmacy]) // or ALLEXCEPT('Rx Data', 'Rx Data'[Provider])
      )
    
    Provider Percent =
      DIVIDE(
        [Prescription Count],
        [Total Provider Prescriptions]
      )
    

    Data table and result:
    enter image description here