+ Reply to Thread
Results 1 to 8 of 8

POWER QUERY: 'Flag' row if it contains the latest date in a category

  1. #1
    Forum Contributor
    Join Date
    04-14-2008
    Location
    Fort Collins, Co
    MS-Off Ver
    2016
    Posts
    107

    Smile POWER QUERY: 'Flag' row if it contains the latest date in a category

    I have data that looks similar to this:

    Model# | Part# | Part last ship date

    Each part will have a last ship date that varies from the others, and each model might have several of the same part that only differ based on the last ship date. I need to flag the latest part last ship date for each model in Power Query. Any help appreciated!

    Example of what I need:

    MODEL | Part | Date | FLAG
    ABC | 123 | 4/23/18 |
    ABC | 123 | 5/18/18 | 1
    DEF | 456 | 5/10/18 | 1
    DEF | 456 | 4/30/18 |
    DEF | 456 | 3/1/17 |

    Thanks!
    Last edited by 4am; 04-23-2018 at 11:13 AM.
    Is That Your Spreadsheet Or Did Your Database Just Throw Up?


  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    Hi 4am,

    I'm not sure you can do this in Power Query. I say that because PQ might have 5 million rows it is filtering and wouldn't know the max until it got through all of them.

    How about using a MaxIfS() formula once you pull your data back into Excel? Would that work for you?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    You can try with Group and Max (date)

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    Hi sandy,

    I was looking at List.Max and List.MaxN from the #shared query but couldn't figure either of them out. I keep thinking that PQ is a line by line process and can pull in millions of rows of data. I don't know how it would keep track of the largest value without needing to pull all lines in first. This thread is on my watch list as I'd like to see and answer too.

  5. #5
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    Hi Marvin,
    First, this example from post#1 is very poor (I don't want to say worse words)
    but (treat this as simple pattern) see attached file:

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    OK 4am and Sandy,

    See if the attached does what you requested. Instead of adding a column with a 1 or nothing, this example simply saved the Max Date rows for a bunch of random Models and Parts. Here is the PQ (M Language) code:
    Please Login or Register  to view this content.
    It is much easier to open the attached file and step though the steps. (I didn't need to write a word of the code above )

    PQ Group By Advanced Max Date.xlsx

  7. #7
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    @Marvin
    Haha, good job.
    But I learned one thing on this forum. Don't do more or less than post#1 request. Poor description? Poor answer
    btw. thanks for reps and feedback

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: POWER QUERY: 'Flag' row if it contains the latest date in a category

    OK,

    Here is a better answer using Power Query.

    If the Max table is done using a Connection Only and then this is Merged with the original table it is much cleaner. The new column is added using a Conditional Column. See the attached and step through the PQ.

    PQ last shipped by Model and Part.xlsx

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Power Query Date Transformation
    By Moggzzz in forum Excel General
    Replies: 2
    Last Post: 03-21-2018, 02:47 PM
  2. Power Query Date Time
    By jcmckeon in forum Excel General
    Replies: 5
    Last Post: 09-12-2017, 02:19 PM
  3. [SOLVED] Power Query: Group by category, list text items on separate rows
    By JimDandy in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 08-05-2017, 12:11 AM
  4. Power Query - Filter by Date
    By brent_milne in forum Excel General
    Replies: 0
    Last Post: 03-16-2017, 10:39 AM
  5. [SOLVED] formula to flag the latest date minus 7 days
    By baz0912 in forum Excel General
    Replies: 8
    Last Post: 05-28-2015, 05:39 AM
  6. Microsoft Query Getting the row with the latest date
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-19-2013, 04:03 AM
  7. Finding latest date with query
    By sumdumgai in forum Access Tables & Databases
    Replies: 1
    Last Post: 10-03-2010, 12:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1