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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
SebaSpotti
Advocate II
Advocate II

Average with fake votes

Hi guys!

 

I have a simple table with a column of votes called Table1[Evaluation]. In this column i can have votes from 0 to 10. I want to calculate the average of this column but in a particular way: remove all 0 and 10; and a number of 0 and 10 equal to the average of the count of the others votes. 

 

An example to better understand:

Table1[Evaluation] = [0,0,1,3,4,5,1,9,8,4,5,10,10,0,10]

Average of Count 1_9 = 1

Calculate the average of this column [1,3,4,5,1,9,8,4,5,0,10]

 

Any suggestions?

Thanks all!

 

Seba

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @SebaSpotti,

 

Can you please try this approach:

Modified Average = 
VAR Count1_9 = 
    COUNTROWS(
        FILTER(
            Table1,
            Table1[Evaluation] >= 1 && Table1[Evaluation] <= 9
        )
    )

VAR UniqueCount1_9 = 
    COUNTROWS(
        DISTINCT(
            FILTER(
                Table1,
                Table1[Evaluation] >= 1 && Table1[Evaluation] <= 9
            )
        )
    )

VAR AvgCount1_9 = 
    DIVIDE(Count1_9, UniqueCount1_9, 0)

VAR LimitedZeros = 
    MIN(
        COUNTROWS(FILTER(Table1, Table1[Evaluation] = 0)),
        AvgCount1_9
    )

VAR LimitedTens = 
    MIN(
        COUNTROWS(FILTER(Table1, Table1[Evaluation] = 10)),
        AvgCount1_9
    )

VAR UpdatedTable = 
    UNION(
        FILTER(Table1, Table1[Evaluation] >= 1 && Table1[Evaluation] <= 9),
        TOPN(LimitedZeros, FILTER(Table1, Table1[Evaluation] = 0)),
        TOPN(LimitedTens, FILTER(Table1, Table1[Evaluation] = 10))
    )

RETURN
    AVERAGEX(UpdatedTable, Table1[Evaluation])

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

3 REPLIES 3
v-linhuizh-msft
Community Support
Community Support

Thanks for the reply from Sahir_Maharaj.

 

Hi @SebaSpotti ,

 

I'll offer another approach.

The simple data is as follows:

vlinhuizhmsft_0-1733290267293.png

 

Please create a measure:

Average = 
VAR _count_1_9=COUNTX(FILTER(ALL('Table1'),NOT'Table1'[Evaluation] IN {0,10}),'Table1'[Evaluation])
VAR _countallwithout0and10=COUNTX(FILTER(ALL('Table1'),NOT'Table1'[Evaluation] IN {0,10}),'Table1'[Evaluation])
VAR _AverageofCount1_9=DIVIDE(_count_1_9,_countallwithout0and10)
VAR _count=COUNTROWS(FILTER(ALL('Table1'),NOT('Table1'[Evaluation] IN {0,10})))
VAR _sum=SUMX(FILTER(ALL('Table1'),NOT('Table1'[Evaluation] IN {0,10})),'Table1'[Evaluation])
RETURN
(_sum+(0+10)*_AverageofCount1_9)/(_count+2)

 

Result:

vlinhuizhmsft_1-1733290691837.png

Best Regards,
Zhu

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly

It works for my need, but I prefer the other solution where the table is "cut". Thanks anyway!

Sahir_Maharaj
Super User
Super User

Hello @SebaSpotti,

 

Can you please try this approach:

Modified Average = 
VAR Count1_9 = 
    COUNTROWS(
        FILTER(
            Table1,
            Table1[Evaluation] >= 1 && Table1[Evaluation] <= 9
        )
    )

VAR UniqueCount1_9 = 
    COUNTROWS(
        DISTINCT(
            FILTER(
                Table1,
                Table1[Evaluation] >= 1 && Table1[Evaluation] <= 9
            )
        )
    )

VAR AvgCount1_9 = 
    DIVIDE(Count1_9, UniqueCount1_9, 0)

VAR LimitedZeros = 
    MIN(
        COUNTROWS(FILTER(Table1, Table1[Evaluation] = 0)),
        AvgCount1_9
    )

VAR LimitedTens = 
    MIN(
        COUNTROWS(FILTER(Table1, Table1[Evaluation] = 10)),
        AvgCount1_9
    )

VAR UpdatedTable = 
    UNION(
        FILTER(Table1, Table1[Evaluation] >= 1 && Table1[Evaluation] <= 9),
        TOPN(LimitedZeros, FILTER(Table1, Table1[Evaluation] = 0)),
        TOPN(LimitedTens, FILTER(Table1, Table1[Evaluation] = 10))
    )

RETURN
    AVERAGEX(UpdatedTable, Table1[Evaluation])

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors