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
Marion
Frequent Visitor

Display nth match

Hi

 

Id like to display the nth match for each row of a dataset.

 

Here is my scenario:

In my first table, I have SKUs and date of sale.

In my second table, I have SKUs and potential suppliers.

There is a many to many relationship between the 2 tables on the SKU column. I merged them so I can have a view on the potential suppliers for each SKU for each date of sale.

Problem is, my records have been duplicated because there are several matches of suppliers for each SKU and date. So Id like to capture the nth vendor in a column rather than in a row.

 

Here below is the data. The measures were provided by @smpa01 . The "First Vendor" column gives the right answer, but "Second Vendor" column is blank. It should display "Bernard"

 

Marion_0-1637069910573.png

 

1st vendor measure =
CALCULATE (
MAXX (
FILTER (
ADDCOLUMNS (
'Table',
"rank",
RANKX (
FILTER ( 'Table', EARLIER ( 'Table'[SKU] ) = 'Table'[SKU] ),
CALCULATE ( MAX ( 'Table'[Date] ) ),
,
DESC
)
),
[rank] = 1
),
[Vendor]
),
ALLEXCEPT ( 'Table', 'Table'[SKU] )
)
 
2ndVendor Measure =
CALCULATE (
MAXX (
FILTER (
ADDCOLUMNS (
'Table',
"rank",
RANKX (
FILTER ( 'Table', EARLIER ( 'Table'[SKU] ) = 'Table'[SKU] ),
CALCULATE ( MAX ( 'Table'[Date] ) ),
,
DESC
)
),
[rank] = 2
),
[Vendor]
),
ALLEXCEPT ( 'Table', 'Table'[SKU] )
)
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Marion ,

In your code, I copy the rank part to a column, you can see there is no rank=2 when SKU="Apple",so it's blank.

vkalyjmsft_0-1637658458920.png

Here's my solution.

1.Create a new table.

vkalyjmsft_1-1637659008543.png

2.Create relationship of the two tables.

vkalyjmsft_2-1637659096388.png

3.Create three measures.

1st = CALCULATE(MAX('Table'[Vendor]),FILTER('Table 2','Table 2'[RANK]=1))
2nd = CALCULATE(MAX('Table'[Vendor]),FILTER('Table 2','Table 2'[RANK]=2))
3rd = CALCULATE(MAX('Table'[Vendor]),FILTER('Table 2','Table 2'[RANK]=3))
vkalyjmsft_3-1637659199258.png

 

I attach my sample bellow to help you to understand.

 

Best Regards,

Community Support Team_kalyj

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

 

 

View solution in original post

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @Marion ,

In your code, I copy the rank part to a column, you can see there is no rank=2 when SKU="Apple",so it's blank.

vkalyjmsft_0-1637658458920.png

Here's my solution.

1.Create a new table.

vkalyjmsft_1-1637659008543.png

2.Create relationship of the two tables.

vkalyjmsft_2-1637659096388.png

3.Create three measures.

1st = CALCULATE(MAX('Table'[Vendor]),FILTER('Table 2','Table 2'[RANK]=1))
2nd = CALCULATE(MAX('Table'[Vendor]),FILTER('Table 2','Table 2'[RANK]=2))
3rd = CALCULATE(MAX('Table'[Vendor]),FILTER('Table 2','Table 2'[RANK]=3))
vkalyjmsft_3-1637659199258.png

 

I attach my sample bellow to help you to understand.

 

Best Regards,

Community Support Team_kalyj

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

 

 

smpa01
Super User
Super User

@Marion  is there any way you can recreate the data model in a small scale and attach here for me to examine please?

Please also mention the desired output for the data set you are supplying.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Marion
Frequent Visitor

Hi smpa01

Sure here is the data and the desired output for columns :

 

   DESIRED OUTPUT
DateSKUVendor1st vendor2nd vendor3rd vendor
01-mai-21ApplePaulPaulBernardFranck
01-mai-21AppleBernardPaulBernardFranck
10-mai-21ApplePaulPaulBernardFranck
10-mai-21AppleBernardPaulBernardFranck
21-mai-21ApplePaulPaulBernardFranck
21-mai-21AppleBernardPaulBernardFranck
07-juin-21ApplePaulPaulBernardFranck
07-juin-21AppleBernardPaulBernardFranck
17-juin-21ApplePaulPaulBernardFranck
17-juin-21AppleBernardPaulBernardFranck
06-août-21AppleFranckPaulBernardFranck
07-sept-21StrawberryMaryMaryFrancknull
20-sept-21StrawberryFranckMaryFrancknull
21-sept-21PineapplePaulPaulnullnull
15-nov-21CherryPaulPaulnullnull

 

Thanks for your help!

amitchandak
Super User
Super User

@Marion , Try with Dense

 

2ndVendor Measure =
CALCULATE (
MAXX (
FILTER (
ADDCOLUMNS (
'Table',
"rank",
RANKX (
FILTER ( 'Table', EARLIER ( 'Table'[SKU] ) = 'Table'[SKU] ),
CALCULATE ( MAX ( 'Table'[Date] ) ),
,
DESC, dense
)
),
[rank] = 2
),
[Vendor]
),
ALLEXCEPT ( 'Table', 'Table'[SKU] )
)

 

Also, order should Asc ?

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

Hi amitchandak 

Thanks for your answer

Dense doesn't change the results. 

Ive modified DESC for ASC yes

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.