Forum Discussion

cmac1's avatar
cmac1
Regular Visitor
9 years ago
Solved

Max Bid

I am new to DAX and am trying to do something that I think should be fairly simple.  I have an auction table where each row is a unique bid for a specific item.  Each bid has its own unique id, bid a...
  • Anonymous's avatar
    Anonymous
    9 years ago

    Hi cmac1,


    You can simple use summarize function to get the max bid amount of each item:

     

    Table 2 = SUMMARIZE(Sheet1,[bidder id],"Max Bid",MAX(Sheet1[bid amount]))

     

    Regards,

    Xiaoxin Sheng

  • TomMartens's avatar
    TomMartens
    9 years ago

    Hey,

     

    in this example I used Power Query to find the max amount for an item, I started with this table (fact)

     

     

    If you open the query editor and look at the query for the the table fact, you will see a step called "Group Rows (to be deleted)", here I used "Transform - Group By". You can delete this step if you want, it is used just for demonstration in this example :-):

     

     

     

    If you have a look at the Formula Bar you will see this:

    = Table.Group(#"Changed Type", {"itemid"}, {{"groupIndex", each _, type table}})

    Here you will find " each _" the underscore represents each row of the base table, if you look at the step "Grouped Rows" you will see that I have replaced the underscore with a nested function call "Table.AddIndexColumn( Table.Sort(...))". Be aware that you have to replace the underscore in the Formula Bar. If you did the replacement, the grouping dialog will not reappear.


    This tweaking is necessary to group by itemid but not to loose the column someoneid (in SQL Server you achieve this by using windowing functions (aggregating without loosing the detail rows).

     

    This nested function call creates an IndexColumn. The Index restarts in each group. The function Table.Sort() sorts the rows in each group in descending order by the column amount

    {{"amount", 1}}

     the 1 represents descending order whereas 0 means ascending order.

     

    Than I

    • expanded the table,
    • renamed the column
    • filtered the rows where the column value is 1
    • merged the table with the table "someone" using the column someoneid to retrieve the value of the column someone

    Hope this helps