Home Forums Data Warehousing Analysis Services DAX in tabular model - returning specific record from child table based upon ordering RE: DAX in tabular model - returning specific record from child table based upon ordering

  • After a great deal of experimenting I managed to deliver a functioning solution, on very much the same premise as my SQL code. You create a calculated column as follows:

    =

    CALCULATE (

    MAXX (

    TOPN (

    1,

    Sales,

    Sales[Sales_Value],

    0,

    Sales[Sales_ID],

    0

    ),

    Sales[Sales_ID]

    ),

    RELATEDTABLE (Sales)

    )

    What this is basically doing is to order the sales table by Sales_Value (descending) and take the top 1 value (all done by TOPN function) - I added Sales_ID to the sort order in case of tied values. This returns a table with one record per customer (the max sales value, because I ordered by Sales_Value descending), so I just have to pull the column I want from the table. I chose to do this using MAXX, though any function that returns a column value would work because there is only one row per client. I can't recall if I needed the RELATED table argument or not (I'm writing this away from my solution) - I think I did because the direction of the join was incorrect.

    Any better suggestions?

    Stuart