Results 1 to 5 of 5

Thread: Minimum Value Given Condition

  1. #1
    Seeker nangys's Avatar
    Join Date
    Jan 2017
    Posts
    11
    Articles
    0
    Excel Version
    2010

    Minimum Value Given Condition



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi,

    I'm trying to figure out a formula that would give me the minium price given the same item ID. See below:

    ID Price Min Price
    A1 162 162
    A1 364 162
    A1 174 162
    A2 295 149
    A2 359 149
    A2 149 149
    A3 430 5
    A3 124 5
    A3 5 5
    A3 126 5

    So far, I can only bring the minimum price in the table with this code:

    let
    Source = Source,
    AddCustom = Table.AddColumn(Source, "Custom", each List.Min(Source[Price]))
    in
    AddCustom

    Thank you for the help

  2. #2
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,854
    Articles
    0
    Excel Version
    O365
    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Price", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Min Price", each List.Min([Price]), type number}})
    in
        #"Grouped Rows"

  3. #3
    Seeker nangys's Avatar
    Join Date
    Jan 2017
    Posts
    11
    Articles
    0
    Excel Version
    2010
    Hi Bob,

    Thank you so much for your reply. This is not exactly what I am looking for since I don't need to group the first column. The final result should look exactly as the example on the original post. Can you advise on how to do that?

    However, this gave me the idea that I can create another query using reference, then "Group by" using the ID column and the Min function on column Price, and then do a merge to the original table. That works but if we can skip it then the better.

    Thanks!

  4. #4
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,454
    Articles
    44
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    No merge necessary. you just need to go a bit further with Bob's solution:

    Code:
    let    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Price", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Min Price", each List.Min([Price]), type number}, {"All Rows", each _, type table}}),
        #"Expanded All Rows" = Table.ExpandTableColumn(#"Grouped Rows", "All Rows", {"Price"}, {"Price"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Expanded All Rows",{"ID", "Price", "Min Price"})
    in
        #"Reordered Columns"
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  5. #5
    Seeker nangys's Avatar
    Join Date
    Jan 2017
    Posts
    11
    Articles
    0
    Excel Version
    2010
    Thank you Ken!

    I was able to adapt it and it works perfectly.

Tags for this Thread

Posting Permissions

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