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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mediumlevel2024
Frequent Visitor

Price Average per selected TopN

Hello everyone,
I currently have the problem that I need the average price per selected TopN. This results in price duplication and the average does not recognize that the individual values should be used.
Example values look as follows:

Article IDArticle ID CompetitorPrice
123341,50
123351,56
123361,56

 

ØN price =
VAR SelectedN = SELECTEDVALUE('Average N'[Average N])
RETURN
CALCULATE(
    AVERAGE(table[price]),
    TOPN(
        SelectedN,
        table,
        table[price],
        ASC
    )
)


If I enter TopN = 1, I get the expected value 1.50. But if I enter TopN = 2, I get the value 1.54 instead of 1.53. This happens because the value 1.56 occurs twice, but the calculation should differentiate according to TopN.

Many thanks in advance

1 ACCEPTED SOLUTION
Rupak_bi
Super User
Super User

Hi,

Run the TopN function on some unique column.

ØN price =
VAR SelectedN = SELECTEDVALUE('Average N'[Average N])
RETURN
CALCULATE(
    AVERAGE(table[price]),
    TOPN(
        SelectedN,
        table,
        table[Article ID],
        ASC
    )
)


Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

View solution in original post

6 REPLIES 6
ThxAlot
Super User
Super User

ThxAlot_0-1725005815070.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Hi thanks for your reply, but it still not working. I do have Prices (sorted) like 9,50€, 9,50€, 10,0€, 10,0€ and 11,30€ and if I chose N = 1 it gives me 9,50€ as average. If I chose N = 2 I would expect an average value of 9,50€ but i receive a value of 9,75€ because this measure skips the second 9,50€.
Any further ideas?

Anonymous
Not applicable

Hi @mediumlevel2024 ,

 

You can consider increasing the value by a very small multiple at the same time to get the ordering, I did simple samples and you can check the results as below:

vtianyichmsft_0-1725243473684.png

vtianyichmsft_1-1725243482590.png

 

Column = RANKX('Table',[Value]*[ID]*0.0000000001,,ASC,Dense)

Measure = var _s = SELECTEDVALUE('Table 2'[Column])
RETURN CALCULATE(AVERAGE('Table'[Value]),TOPN(_s,'Table',[Value],ASC))

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Rupak_bi
Super User
Super User

Hi,

Run the TopN function on some unique column.

ØN price =
VAR SelectedN = SELECTEDVALUE('Average N'[Average N])
RETURN
CALCULATE(
    AVERAGE(table[price]),
    TOPN(
        SelectedN,
        table,
        table[Article ID],
        ASC
    )
)


Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Hello, this tip was very helpful. I grouped the prices according to the article number and then inserted an index. The index is now used in my measure for clear assignment.
Many thanks

you are welcome



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.