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
santhidhanuskod
Regular Visitor

TopN records within custom table

Hi,

 

I have created 2 custom tables from the main table using DAX  query.

Active milestones = FILTER('Live Query', ('Live Query'[workflow_stage_name] IN {"In Progress","In Progress - Green","In Progress - Amber","New","In Progress - Red" }))
 
Completed milestones = FILTER('Live Query', AND(
            'Live Query'[workflow_stage_name] = "Completed",
            'Live Query'[planned_due_date].[Date] >= TODAY() - 14))
 
I have a requirement to pick up top 5 records from active milestones + all completed milestones, dispaly in table chart.
I wrote the query as
 
Table = UNION(TOPN(100,'Active milestones', 'Active milestones'[planned_due_date].[Date],ASC),'Completed milestones')
 
But this is not working, it returns only completed milestones. If I pick up only active milestones in table and apply visual filter (top n), then it works....If I try the same in dax, it is not working....
 
please help

 

3 REPLIES 3
MVenables
Advocate II
Advocate II

Hi,

 

Instead of using a TOPN Measure have you considered added a filter to the visual. Advanced filtering then selecting how many by TOPN as per my example below. I have filter by my 'Sell' (Sales Measure)

MVenables_0-1711368577283.png

Thank you

Anonymous
Not applicable

Hi @santhidhanuskod 

 

Is your problem solved? If not, can you provide detailed sample pbix file and the results you expect.So that I can help you better. Please remove any sensitive data in advance.

 

 

Best Regards,

Jayleny

 

 

 

 

amitchandak
Super User
Super User

@santhidhanuskod , You should create a measure

//change to include the filter from first column

 

M1  = countrows( FILTER('Live Query', AND(
'Live Query'[workflow_stage_name] = "Completed",
'Live Query'[planned_due_date].[Date] >= TODAY() - 14))   )

 

Then have top N Measure

calculate([M1] ,TOPN(3,allselected('Active milestones'[planned_due_date]),[M1]), values('Active milestones'[planned_due_date]))

 

choose the correct columns as needed

 

Learn Power BI: Dynamic TOPN using TOPN/Window and Numeric parameter: https://youtu.be/vm2mdEioQPQ

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.