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
mmcarthur
Frequent Visitor

Creating a calculated field that excludes top 15% of rows based on a column

I am currently converting a Tableau report over to Power BI and came across a dashboard that needs to have a parameter slicer that gives the option to exclude different percentages of rows based on the longest days of service. This gives the user the option to find averages based on the bottom 85% of days of service, but still leaves the option to calculate the averages based on all of the rows as well. I've tried to rework it in Power BI, but I'm having trouble allowing the percent excluded to remove rows when changed (excluding the rows where days of service are the longest) rather than multiply the individual Days of Service by a percentage. I was wondering what sort of DAX or M code would allow me to create either a measure or calculated column to allow for this?

Thanks!

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @mmcarthur ,

According to your description, I create a sample.

vkalyjmsft_0-1658229936010.png

Here's my solution, create a parameter.

vkalyjmsft_1-1658230009351.png

Then create a measure,

Average =
AVERAGEX (
    TOPN (
        'Parameter'[Parameter Value] * COUNTROWS ( ALL ( 'Table' ) ),
        'Table',
        'Table'[Days of Service], ASC
    ),
    'Table'[Days of Service]
)

 Put the measure in a card visual, get dynamic average value based on the parameter slicer.

vkalyjmsft_2-1658230085269.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @mmcarthur ,

According to your description, I create a sample.

vkalyjmsft_0-1658229936010.png

Here's my solution, create a parameter.

vkalyjmsft_1-1658230009351.png

Then create a measure,

Average =
AVERAGEX (
    TOPN (
        'Parameter'[Parameter Value] * COUNTROWS ( ALL ( 'Table' ) ),
        'Table',
        'Table'[Days of Service], ASC
    ),
    'Table'[Days of Service]
)

 Put the measure in a card visual, get dynamic average value based on the parameter slicer.

vkalyjmsft_2-1658230085269.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I tried this DAX equation and everything works except the data does not change when the parameter slicer value gets changed. Any thoughts on what I could be missing to cause this to happen?

Hi @mmcarthur ,

Do you use the What if parameter under the Modeling ribbon, and then reference the 'Parameter'[Parameter Value] in the measure(not a calculated column)?

vkalyjmsft_0-1659602563875.png

Best Regards,
Community Support Team _ kalyj

Greg_Deckler
Super User
Super User

@mmcarthur Likely you would want to use the TOPN function in a measure. TOPN function (DAX) - DAX | Microsoft Docs


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Is there any line of code to exclude the top 15% of rows in DAX?

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.