Forum Discussion

JamesCarter's avatar
JamesCarter
Frequent Visitor
5 years ago
Solved

Dax Measure to return a single value from a column when using Min function on a different column

Hi
I need to create a measure (and it has to be a measure, not a column, due wider reports/ calculations/ interdependencies). I need that measure to return the Ref which relates to the first start date. In the event that the first start date occurs twice or more, I need it to return the first occurrence. 

 

Example data is below:

RefStart Date
12345601/01/2021
78912303/04/2021
45601909/05/2021
83921312/05/2021
12745901/01/2021
29302227/02/2021
93485913/02/2021
29485015/04/2021
93057318/04/2021
293850229/05/2021
75439223/03/2021

 

So, from my data above, the first start date is 01/01/21 - that occurs with refs 123456 and 127459, so I'd want the answer to be 123456. 


I can obviously get a measure which lists the first start date using Min, but beyond that I'm hitting a wall.

Would be very grateful for any advice.
Thanks

  • JamesCarter try this meaure

     

    Top Ref = CALCULATE ( MIN ( Ref[Ref] ), TOPN ( 1, ALLSELECTED ( Ref ), Ref[Start Date], ASC ) )

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • Hi,

    Try these measures

    First date = MIN(Data[Start Date])
    Measure = FIRSTNONBLANK ( TOPN ( 1, VALUES (Data[Ref]), [First date],ASC ), 1 )

    Drag the second measure to a card visual.  The result will be 123456.

7 Replies

  • Hi,

    Try these measures

    First date = MIN(Data[Start Date])
    Measure = FIRSTNONBLANK ( TOPN ( 1, VALUES (Data[Ref]), [First date],ASC ), 1 )

    Drag the second measure to a card visual.  The result will be 123456.

    • JamesCarter's avatar
      JamesCarter
      Frequent Visitor

      Thanks Ashish, 
      Absolute superstar. That worked a treat. 
      I tweaked slightly to make the first measure a variable and I'm absolutely getting the result. 
      Brilliant stuff - very grateful. I'd been playing with FIRSTNONBLANK, MIN and TOPN but just couldn't get it - haven't used ASC before. That's a new string to the bow!
      Thanks again


    • JamesCarter's avatar
      JamesCarter
      Frequent Visitor

      Actually ignore that bit about variable. 
      I thought it had worked, but it hadn't - so I've reverted to what you did and that remains perfect.

      Thanks again
      James

  • JamesCarter try this meaure

     

    Top Ref = CALCULATE ( MIN ( Ref[Ref] ), TOPN ( 1, ALLSELECTED ( Ref ), Ref[Start Date], ASC ) )

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • JamesCarter's avatar
      JamesCarter
      Frequent Visitor

      Hi parry2k 
      Thanks so much for responding and for your proposal. 
      I couldn't quite get it to work (it wouldn't let me call the start date). Sure it's something I did wrong in translating the measure to my actual table. 
      Happily Ashish_Mathur 's solution worked, but I'm really grateful for your time and offer of help.
      I do love the support people offer on these forums.
      Thanks again
      James

    • JamesCarter's avatar
      JamesCarter
      Frequent Visitor

      Hi parry2k 
      I really should properly wait to investigate before replying - lesson for the future.
      I've found what I did wrong in the previous attempt and yes, absolutely, your solution worked.
      Thanks again