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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
mysho999
Frequent Visitor

TOP N

Hi
i need advice.

I have a spreadsheet of data.

mysho999_0-1593409537191.png

 

I would need to make two tables:

The first table will show the TOP 2 department by Duration
The second table will be the top1 Code and Code description within the top Department.

 

Example
Table 1: TOP2 departments (ENG / Maintenance)

mysho999_1-1593409708815.png

 


Table 2: TOP 1 Code / Code description from ENG and TOP1 code / code description from Maintenance

mysho999_2-1593409794584.png

 

 

Or if it was possible to do everything in one table, it would be fantastic.

 

DATA SOURCE: https://drive.google.com/drive/folders/1cQF3zhHtCLjaFDg7CLSyerMW1qtWbdz6?usp=sharing 

Well thank you

6 REPLIES 6
mysho999
Frequent Visitor

HI @Anonymous 

 

thanks a lot, I'll try today.

just a question ... Will the code work dynamically? What do I think ... Every day, a few hundred rows are added to the database. This means that there can be two different TOP departments every day.

Thank you

Anonymous
Not applicable

Hi @mysho999 ,

 

For the first table, it's dynamic.

 

For the second table, I hard-code it to calculate the top 1 for ENG and Maintenance department as you said.

If you want to change it, you need to change the label in the DAX.

 

Aiolos Zhao

Hi @Anonymous 

1. I would need to add a filter by date (TOP 3 department as well as Code, code de ... will change based on time range)
2. Probably more complicated ... In table 2 I only need to show data based on the TOP 3 department. (for example: if in table 1 there is a top three x, y, z then in table 2 I need to visualize TOP1 only for x, y, z. If TOP 3 in the first table changes, TOP 1 in the second table will also change.)
Snímka.PNG
Anonymous
Not applicable

Hi @mysho999 ,

 

I create 2 tables using DAX, hope that's what you want:

 

TOP N2.PNGTOP N.PNG

 

Table = TOPN(2,SUMMARIZE('Hárok1','Hárok1'[Deparment],"total duration",SUM('Hárok1'[Duration (min)])),[total duration],DESC)

 

Table 2 = UNION(TOPN(1,SUMMARIZE(FILTER('Hárok1','Hárok1'[Deparment] in {"ENG"}),'Hárok1'[Deparment],'Hárok1'[Code],'Hárok1'[Code description],"top code duration",SUM('Hárok1'[Duration (min)])),[top code duration],DESC),
                TOPN(1,SUMMARIZE(FILTER('Hárok1','Hárok1'[Deparment] in {"Maintenance"}),'Hárok1'[Deparment],'Hárok1'[Code],'Hárok1'[Code description],"top code duration",SUM('Hárok1'[Duration (min)])),[top code duration],DESC))

 

Please try.

Aiolos Zhao

adityavighne
Continued Contributor
Continued Contributor

@mysho999 

at department filter you will get Top N filter

so select Top N and By Value - Duration

tomn.PNG

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.