Forum Discussion

gillyr7's avatar
gillyr7
Frequent Visitor
7 years ago
Solved

Keep Blank Rows After Filter And Create Average of all Others

I am having a trouble with a model I am building in Power BI Desktop. I have a table, and in the end, I am trying to calculate the average price grouped by Affiliation and Code.

 

The caveat, is that I need there to always be every Affiliation and every code regardless of the filters. Please see my picture I included. Each affiliation (A,B,C) has all three codes (1,2,3). Affilation 3 however, only has one of the payers. When I filter to Payer 'One', Affilation C goes away.

 

I am wondering if there is a way to keep Affiliation C and all three codes there regardless of the filter, and if it is missing, calculate the average of the others to throw into the blank cells. I tried Summarize but could not figure it out.

 

My formula to calculate the average price (it's actually median), is below:

CALCULATE(MEDIAN(Merge1[PRICE]),ALLEXCEPT(Merge1,Merge1[AffiliationCode],Merge1[Affiliation Level II]))
 
I can adjust this if needed.

 

  • Anonymous's avatar
    Anonymous
    7 years ago

    The answer is maybe.  It will depend on your slicers and if you made to that the table relationship has the security filters set to 1 way.

     

    If your slicers are set up to filter based on the fields in your merge table, then only the number considered by my measure will be impacted.  The list of Key values will be unfiltered.

     

    You mentioned a good point, the way my measure is set up. If a Key connects to no values it will return blank.  A Blank is different to a zero. So the question for you would be, do you want blanks to be zero?  If thats the case, add a "+ 0" after the SUM()

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    There are a few ways you could solve this.  If you want to make sure you get every single Afflication and Code, I would suggest building a table using PowerQuery that contains 1 row for every combination.

     

    This table could be something as simple as a Key, which is a concatination of the Afflication and Code of that row, then having a column for those values separately.

     

    In your merge1 table, include an extra field that uses the same concatination. You will now be able to link the Key table in a 1 to many relationship with your merge1 table.

     

    From here you could have a measure that does a median of the result for each entry in this key table.  Such a measure might look like:

    Median of Sums = MEDIANX(
    	VALUES(KeyTable[Key]),
    	SUM(Merge1[PRICE])
    )
    • gillyr7's avatar
      gillyr7
      Frequent Visitor

      Thanks for the response. I will give this a try. I have slicers set up on my Merge1 table, will the price be filtered by the slicers when calculating on the key table?

       

      Also, from your formula, it does not look like there is anything there for the missing values. For example, if you saw my screenshot, Affiliation C did not have Payer "1". If the slicer is selected to Payer "1", is there a way to have Affiliation C calculate the median for all affilations since C does not have any data? Thanks.

      • Anonymous's avatar
        Anonymous
        Not applicable

        The answer is maybe.  It will depend on your slicers and if you made to that the table relationship has the security filters set to 1 way.

         

        If your slicers are set up to filter based on the fields in your merge table, then only the number considered by my measure will be impacted.  The list of Key values will be unfiltered.

         

        You mentioned a good point, the way my measure is set up. If a Key connects to no values it will return blank.  A Blank is different to a zero. So the question for you would be, do you want blanks to be zero?  If thats the case, add a "+ 0" after the SUM()

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi gillyr7 

    Create a measure and keep the interaction among the visuals as below

    Measure = AVERAGE('Table'[Price])

    Add them in a matrix.

     

    Best Regards
    Maggie

     

    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.