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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MortimerMcFly
Frequent Visitor

Average of Top 3 and Bottom 3 Values

Hey @all,

 

I have a problem I was trying to solve for a couple of time now. 

 

What am I trying to do. What do I need? 

I want to create a visual (line chart) which shows the average of the top 3 values and the bottom 3 values over a period of time. 

MortimerMcFly_0-1721200061937.png

Thank you for your help.

 

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@MortimerMcFly 

you can try this

Measure =
VAR _top=TOPN(3,'Table','Table'[value],DESC)
VAR _bottom=TOPN(3,'Table','Table'[value],ASC)
return (sumx(_top,[value])+sumx(_bottom,[value]))/6
 
11.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

A third Variable did the trick: 

C_D12 =
VAR Table_ID1 = Filter('Table1','Table1'[market]="D_12")
VAR _top3 = TOPN(3,Table_ID1,'Table1'[price],DESC)
VAR _bot3 = TOPN(3,Table_ID1,'Table1'[price],ASC)

RETURN
    DIVIDE(SUMX(_top3,'Table1'[price])+SUMX(_bot3,'Table1'[price]),6)

View solution in original post

12 REPLIES 12
ryan_mayu
Super User
Super User

@MortimerMcFly 

you can try this

Measure =
VAR _top=TOPN(3,'Table','Table'[value],DESC)
VAR _bottom=TOPN(3,'Table','Table'[value],ASC)
return (sumx(_top,[value])+sumx(_bottom,[value]))/6
 
11.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




It did the trick, thank you! 
Do you know hot include a filter statement? I tried this: Solved: How to include a filter in a topN dax function? - Microsoft Fabric Community but it is not working in my case. Cheers!

then pls update the sample data and expected output. Let me have a try.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




 

I need the Top 3 and Bottom 3 solution but with an additional filter so i get the average for different types. 

13.01.2024 14:45QH74,7
13.01.2024 08:15QH92,03
13.01.2024 17:30H90,03
13.01.2024 23:30H60,39
13.01.2024 07:45QH98,33
13.01.2024 09:15QH88,11
13.01.2024 16:30QH83,8
13.01.2024 16:45QH88,19
13.01.2024 22:15H71,03
13.01.2024 18:30QH81,87
13.01.2024 18:00H94,11
13.01.2024 06:45QH78,13
13.01.2024 22:00QH94,29
13.01.2024 23:45QH52,86
13.01.2024 09:45H87,17
13.01.2024 18:15QH88,82
13.01.2024 23:15QH73,41
13.01.2024 10:00H90,09




 

what are the types? H and QH?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Yes. Sorry I posted it under your other answer. Missclicked.. 

could you pls paste the data here?(not the screenshot). And what's the expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




13.01.2024 14:45 QH 74,7 
13.01.2024 08:15 QH 92,03 
13.01.2024 17:30 H 90,03 
13.01.2024 23:30 H 60,39 
13.01.2024 07:45 QH 98,33 
13.01.2024 09:15 QH 88,11 
13.01.2024 16:30 QH 83,8 
13.01.2024 16:45 QH 88,19 
13.01.2024 22:15 H 71,03 
13.01.2024 18:30 QH 81,87 
13.01.2024 18:00 H 94,11 
13.01.2024 06:45 QH 78,13 
13.01.2024 22:00 QH 94,29 
13.01.2024 23:45 QH 52,86 
13.01.2024 09:45 H 87,17 
13.01.2024 18:15 QH 88,82 
13.01.2024 23:15 QH 73,41 
13.01.2024 10:00 H 90,09 

 

I need the Top 3 and Bottom 3 solution but with an additional filter so i get the average for different types. 

i think the previous solution can work on this scenario as well.

11.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I dont get the expected result in a matrix visual..

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




A third Variable did the trick: 

C_D12 =
VAR Table_ID1 = Filter('Table1','Table1'[market]="D_12")
VAR _top3 = TOPN(3,Table_ID1,'Table1'[price],DESC)
VAR _bot3 = TOPN(3,Table_ID1,'Table1'[price],ASC)

RETURN
    DIVIDE(SUMX(_top3,'Table1'[price])+SUMX(_bot3,'Table1'[price]),6)

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.