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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
adii
Helper I
Helper I

How to tak 3 recent row from table in DAX

Hello , 

I'm looking solve my problem .

I have a table with column A with datetime 

Column A 
2024-01-11 10:54:55

2024-01-11 10:54:33

2024-01-11 10:51:00

2024-01-11 10:51:00

2024-01-11 10:50:23

 

Column B

123

175

155

122

125

 

i would like recive table ( Column A and B) with first 4 row based on Datetime (Ascending)

 

which function I should use ? 
I thought about RANKX , but that function rankx needs measure 

 

thanks 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @adii ,

 

Are you referring to finding the ordering of [column A] based on the grouping of [column C]?

You can use the following calculated columns:

Rank =
RANKX(
    FILTER(
        ALL('Table'),'Table'[ColumnC]=EARLIER('Table'[ColumnC])),'Table'[ColumnA],,DESC,Dense)

vyangliumsft_0-1705314191969.png

 

Best Regards,

Liu Yang

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

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi  @adii ,

 

Are you referring to finding the ordering of [column A] based on the grouping of [column C]?

You can use the following calculated columns:

Rank =
RANKX(
    FILTER(
        ALL('Table'),'Table'[ColumnC]=EARLIER('Table'[ColumnC])),'Table'[ColumnA],,DESC,Dense)

vyangliumsft_0-1705314191969.png

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

Hi  @adii ,

 

Here are the steps you can follow:

1. Create calculated column.

Rank =
RANKX(
    'Table','Table'[ColumnA],,DESC,Dense)

vyangliumsft_0-1705034547904.png

2. Create calculated table.

Table 2 =
FILTER(
    'Table',
[Rank]<=3)

3. Result:

vyangliumsft_1-1705034547905.png

 

Best Regards,

Liu Yang

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

Perfect it's working thanks . 
so can you help me in a little more tricky example . Now I need do the same like above but I got extra column C with date (year-month-day) and a would like make ranking for each day separately.

? I'n trying use 

calculate( Rank, All(table[column C]) but doesn't work .. 

 

adii
Helper I
Helper I

What you think about add column with numer increment ? Start from 1 to 4 

gmachowiak
Frequent Visitor

I'd use TOPN fucntion:

    TOPN(
        3,
        'Table',
        'Table'[Column1],
        ASC
    )

Doesn't work ,  it's multiply values, should be scalar  

lbendlin
Super User
Super User

use the WINDOW function with relative addressing from -3 to -1

Doesn't work 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.