Forum Discussion

chudson's avatar
chudson
Helper IV
7 years ago
Solved

Returning a Value Using LASTNONBLANK

Hi,   I have a table that has SalesRep and associated Sales Manager at the time of an order in my FactSales table.  My FactSales table is sorted from oldest to most recent order date and I'm trying...
  • Cmcmahan's avatar
    7 years ago

    It might be sort of a flippant reply, but if LASTNONBLANK is getting you the oldest manager and you want the newest manager, would FIRSTNONBLANK work?

     

    I would use TOPN and create this as a measure. You can change it to use OrderNum instead of OrderDate, if that's a better indicator of "current". Sample .pbix attached.

    CurrentManager = CALCULATE( SELECTEDVALUE('Dim Sales Rep'[SalesManagerCode]), TOPN( 1, 'Dim Sales Rep', 'Dim Sales Rep'[Order Date], DESC))

     

  • dax's avatar
    dax
    7 years ago

    Hi chudson, 

    You also could try below measure to see whether it works or not

    Measure 5 = CALCULATE(Min('Sales Rep'[SalesManagerCode]), FILTER(ALLEXCEPT('Sales Rep','Sales Rep'[SalesRepCode]),'Sales Rep'[Order Date]=MAX('Sales Rep'[Order Date])))

    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.