Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
gillyr7
Frequent Visitor

Keep Blank Rows After Filter And Create Average of all Others

Capture.JPG

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.

 

1 ACCEPTED SOLUTION
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()

View solution in original post

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @gillyr7 

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

Measure = AVERAGE('Table'[Price])

Add them in a matrix.

1.png

 

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.

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])
)

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
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()

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.