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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
axk180022
Helper II
Helper II

Find the latest 2 dates

axk180022_0-1631648303702.png

 

Expected output

CALCULATIONDATETIME  INVNETSERIALID   GENERATORHOURS
9/25/2020CVS-0028154
11/23/2020CVS-0028359
5/13/2021CVS-0039122
5/27/2021CVS-0039159

 

I have this table, I need just filter the 2 latest dates for each inventserialID having an existing Generator hours. 

 

2 LAST DATES = 
Var _invent = FIRSTNONBLANK('Table'[INVENTSERIALID],"")
vAR _latestdate = CALCULATE(max('Table'[CALCULATIONDATETIME]),ALLEXCEPT('Table','Table'[INVENTSERIALID]))
vAR _2ndlatest = MAXX(FILTER(filter('Table','Table'[INVENTSERIALID]=_invent),'Table'[CALCULATIONDATETIME]<_latestdate),'Table'[CALCULATIONDATETIME])
RETURN
IF('Table'[CALCULATIONDATETIME] IN {_latestdate,_2ndlatest},'Table'[CALCULATIONDATETIME])

 

The above worked but does not take the generator hours that has existing value in it, just takes max and 2nd max date for each serialID. Can someone tell me what changes need to be made.

 

I require last and second last date for each serialid having an existing genratorhours( highlighted in yellow).

 

 

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@axk180022 and here is the output:

 

parry2k_0-1631651689250.png

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
parry2k
Super User
Super User

@axk180022 

easure 2 = 
CALCULATE ( 
    SUM ( Inv[GENERATORHOURS] ),
    KEEPFILTERS ( 
        TOPN ( 
            4, 
            FILTER ( 
                ALLSELECTED ( Inv ), 
                Inv[INVENTSERIALID] = MAX ( Inv[INVENTSERIALID] ) && 
                Inv[GENERATORHOURS] > 0 
            ), 
            Inv[CALLACTIONDATETIME], DESC 
        ) 
    ) 
)

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi,

 

This measure worked perfectly for me, but I would want to consider the ones which has values, it is picking up the blanks for top 4, can you please tell me what needs to be included.

 

@parry2k 

parry2k
Super User
Super User

@axk180022 and here is the output:

 

parry2k_0-1631651689250.png

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@axk180022 try this measure:

 

 

Measure 2 = 
CALCULATE ( 
    SUM ( Inv[GENERATORHOURS] ),
    KEEPFILTERS ( 
        TOPN ( 
            2, 
            FILTER ( 
                ALLSELECTED ( Inv ), 
                Inv[INVENTSERIALID] = MAX ( Inv[INVENTSERIALID] ) && 
                Inv[GENERATORHOURS] > 0 
            ), 
            Inv[CALLACTIONDATETIME], DESC 
        ) 
    ) 
)

 

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi Parry,

 

Can you please tell me what should be the change in the measure if I need last 4 dates? 

 

@parry2k 

parry2k
Super User
Super User

@axk180022 can you paste the data in the table instead of the image.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

CALLACTIONDATETIME    INVENTSERIALID    GENERATORHOURS
6/23/2020 14:55CVS-0022600
6/24/2020 12:31CVS-0027749
6/25/2020 17:32CVS-0027749
7/28/2020 13:10CVS-0027749
8/19/2020 18:30CVS-0020
8/31/2020 13:15CVS-0020
9/19/2020 14:00CVS-0028103
9/25/2020 21:30CVS-0028154
11/18/2020 17:00CVS-0020
11/23/2020 19:40CVS-0028359
12/16/2020 13:30CVS-0038479
3/9/2021 16:43CVS-0038804
4/27/2021 21:55CVS-0035107
5/13/2021 15:41CVS-0039122
5/27/2021 14:00CVS-0039159
6/16/2021 19:07CVS-0030

 

@parry2k 

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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