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
Anonymous
Not applicable

Second Last entry in data set

My data contains submit date, valid entry and RAG status, I want rag status of employees with valid entry yes and date submit is second last.

 

DAX should filter the valid  = Yes, and Employee Code = Employee Code and provide rag status of second max date in submit date.

 

Below is table, first four column I have in table and I want to add Previous RAG column.

 

 

 

Date SubmitEmp CodeValidRAGPrevious RAG
1-Jan-2019123YesRedGreen
18-Dec-2018123YesGreen 
1-Jan-2019123NoRed 
1-Dec-20201444YesRedAmber
1-Nov-20181444YesAmber 

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

You can create two Calculated columns.

 

Rank By Date =

VAR _rank =

    RANKX (

        FILTER (

            'Table',

            'Table'[Valid] = "Yes"

                && 'Table'[Emp Code] = EARLIER ( 'Table'[Emp Code] )

        ),

        'Table'[Date Submit],

        ,

        DESC,

        DENSE

    )

RETURN

    IF ( 'Table'[Valid] = "No", BLANK (), _rank )

 

Previous RAD =

VAR val =

    MAXX (

        FILTER ( 'Table', [Rank By Date] = 2 && [Emp Code] = EARLIER ( [Emp Code] ) ),

        [RAG]

    )

RETURN

    IF ( 'Table'[Rank By Date] = 1, val, BLANK () )

 

The result looks like this:

v-cazheng-msft_0-1619429648686.png

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? 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

2 REPLIES 2
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

You can create two Calculated columns.

 

Rank By Date =

VAR _rank =

    RANKX (

        FILTER (

            'Table',

            'Table'[Valid] = "Yes"

                && 'Table'[Emp Code] = EARLIER ( 'Table'[Emp Code] )

        ),

        'Table'[Date Submit],

        ,

        DESC,

        DENSE

    )

RETURN

    IF ( 'Table'[Valid] = "No", BLANK (), _rank )

 

Previous RAD =

VAR val =

    MAXX (

        FILTER ( 'Table', [Rank By Date] = 2 && [Emp Code] = EARLIER ( [Emp Code] ) ),

        [RAG]

    )

RETURN

    IF ( 'Table'[Rank By Date] = 1, val, BLANK () )

 

The result looks like this:

v-cazheng-msft_0-1619429648686.png

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

new column =
var _rank = rankx(filter(Table, [Emp] = earlier([Emp ])), [Date Submit],,desc, dense)
Var _status = maxx(filter(Table, [Emp] = earlier([Emp ]) && _rank =2),[status])
return
if(_rank =1,_status, blank())

 

if _rank does not work create a rank column first

rank = rankx(filter(Table, [Emp] = earlier([Emp ])), [Date Submit],,desc, dense) 

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.