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
Cookistador
Helper III
Helper III

Top n With matrix and date

Hi everyone,

 

I'm facing an issue with Power BI & Matrice, I have some projects with task associated, I created a matrix in which I would like for each project to return the 2 with the earliest start date

So this a dataset sample

Project NameTaskStart Date
ProjectAPython script01/01/2023
ProjectAJava script16/01/2023
ProjectAC# Script02/02/2023
ProjectBC++ Script05/03/2023
ProjectBC Script29/03/2023
ProjectBRuby Script17/04/2023
ProjectCPowershell Script02/03/2023
ProjectCRust Script11/04/2023
ProjectCJS Script17/05/2023
ProjectCNode Script01/06/2023

 

And I would like to get something like:

ProjectA  
 Python script01/01/2023
 Java script16/01/2023
ProjectB  
 C++ Script05/03/2023
 C Script29/03/2023
ProjectC  
 Node Script01/02/2023
 Powershell Script

02/03/2023

 

Any idea of how could I achieve that?

I tried Top N but it returns me something weird 

 

Many thanks in advance for your help

1 ACCEPTED SOLUTION

rnk = 
var a = CALCULATETABLE(SUMMARIZE('Table',[Task],"md",min([Start Date])),REMOVEFILTERS('Table'[Task]))
return rank(SKIP,a,ORDERBY([md],ASC))

 

You cannot rank duplicate items. The SUMMARIZE part removes that ambiguity

 

lbendlin_0-1696372230873.png

 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

lbendlin_0-1696087942912.png

rnk = RANK(SKIP,Allselected('Table'),ORDERBY('Table'[Start Date]),LAST,PARTITIONBY('Table'[Project Name]))

Note this is done as a measure , just in case. If you don't expect user interaction you can change it to a calculated column.

Thank you for your help

I still have a last blocking point 😕
If two tasks have the same name in a project, it doesn't work
For my ProjectC, I added the following value 

ProjectCPowershell Script02/03/2023
ProjectCRust Script09/04/2023
ProjectCRust Script11/04/2023
ProjectCJS Script17/05/2023
ProjectCNode Script01/02/2023

 

So as you see, there are two tasks called Rust script, but the measure doesn't return any rank for this value

Cookistador_0-1696362807761.png

 

I tried a few things like creating a kind of sugorate key or adding another parameter in the order by but it doesn't work

 

Any clue of waht I can do?

 

rnk = 
var a = CALCULATETABLE(SUMMARIZE('Table',[Task],"md",min([Start Date])),REMOVEFILTERS('Table'[Task]))
return rank(SKIP,a,ORDERBY([md],ASC))

 

You cannot rank duplicate items. The SUMMARIZE part removes that ambiguity

 

lbendlin_0-1696372230873.png

 

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.