Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello I am looking for a code like the trimmean function in excel.
The previvous posts i checked didn't help me finding a solution.
Maybe someone can help me with an kind of sample code and what i have to replave inside of the code...
Solved! Go to Solution.
Hi @DSchmndtk ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:
Create a Rank column
Rank = RANKX('Table',[Value],,ASC)
Create a measure
Trimmed Mean =
VAR _percentage = 0.3
VAR _startRank = FLOOR(COUNTROWS('Table')*_percentage/2+1,1)
VAR _endRank = COUNTROWS('Table')*(1-FLOOR(_percentage/2,0.1))
VAR _sum =
CALCULATE(
SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Rank] <=_endRank && 'Table'[Rank] >= _startRank
)
)
VAR _count = COUNTROWS('Table')*(1-FLOOR(_percentage/2,0.1)*2)
RETURN
_sum/_count
Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @DSchmndtk ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:
Create a Rank column
Rank = RANKX('Table',[Value],,ASC)
Create a measure
Trimmed Mean =
VAR _percentage = 0.3
VAR _startRank = FLOOR(COUNTROWS('Table')*_percentage/2+1,1)
VAR _endRank = COUNTROWS('Table')*(1-FLOOR(_percentage/2,0.1))
VAR _sum =
CALCULATE(
SUM('Table'[Value]),
FILTER(
'Table',
'Table'[Rank] <=_endRank && 'Table'[Rank] >= _startRank
)
)
VAR _count = COUNTROWS('Table')*(1-FLOOR(_percentage/2,0.1)*2)
RETURN
_sum/_count
Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
In Power BI, you can replicate the TRIMMEAN function using DAX (Data Analysis Expressions). Below is a DAX formula to calculate the trimmean:
TrimMean =
VAR Data = SUMMARIZE('Table', 'Table'[Value])
VAR Percent = 0.2 -- Change this to the desired percentage
VAR Count = COUNTROWS(Data)
VAR TrimCount = INT(Count * Percent)
RETURN
AVERAGEX(
TOPN(Count - 2 * TrimCount, Data, 'Table'[Value], ASC),
'Table'[Value]
)
Here's what you need to do:
Here's a step-by-step guide:
For example, if you have a table named Sales and a column named Amount, your DAX formula would look like this:
TrimMean =
VAR Data = SUMMARIZE('Sales', 'Sales'[Amount])
VAR Percent = 0.2 -- Change this to the desired percentage
VAR Count = COUNTROWS(Data)
VAR TrimCount = INT(Count * Percent)
RETURN
AVERAGEX(
TOPN(Count - 2 * TrimCount, Data, 'Sales'[Amount], ASC),
'Sales'[Amount]
)
This DAX formula creates a new measure named TrimMean that calculates the trimmean of the Amount column in the Sales table, removing 20% of the data from the top and bottom tails.
You can then use this TrimMean measure in your reports and visuals just like any other measure.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
8 | |
8 |
User | Count |
---|---|
13 | |
12 | |
11 | |
10 | |
8 |