I have a Dataset[] with some data and a TON of columns. Each row contains several columns for dates, which contain DateObject values, but they aren't always populated. If a value is Null, I've replaced it with Missing[] for a) prettier display in Dataset visualization, b) to allow use of MissingQ and DeleteMissing.

Here's my question. I am trying to get a single definitive date for each row based on the first non-Missing value. It's possible that ALL values will be missing. In that case either nothing needs to be returned or a Missing["No date"] is fine.

What I have so far is very ugly and crude, and I'm wondering if there's a more elegant way to do this, that simply escapes me for now?

  Take[ DeleteMissing@#, UpTo[1] ]& /@
  Normal@Values@encounters[ All,
    {"ArriveDTS", "EstimatedArriveDTS", "RegistrationDTS", 
     "TriageDTS", "InpatientAdmitDTS", "AssignToLocationDTS", 
     "DischargeDTS", "DepartDTS", "EstimatedDepartDTS", 
  • 2
    $\begingroup$ SelectFirst[Not @* MissingQ]? $\endgroup$
    – Pillsy
    Commented Apr 20, 2017 at 0:48
  • $\begingroup$ @Pillsy Please add as an answer. That worked wonders! Thank you! Finished product: encounters[All, SelectFirst[Not@*MissingQ]@*KeyTake[{"ArriveDTS", "EstimatedArriveDTS", "RegistrationDTS", "TriageDTS", "InpatientAdmitDTS", "AssignToLocationDTS", "DischargeDTS", "DepartDTS", "EstimatedDepartDTS", "PreRegistrationDTS"}]] $\endgroup$ Commented Apr 20, 2017 at 1:47

1 Answer 1


The SelectFirst function does exactly what you want. As you note in your comment ( :) ), this will work:

encounters[All, SelectFirst[Not@*MissingQ]@*KeyTake[{"ArriveDTS",  
  "EstimatedArriveDTS", "RegistrationDTS", "TriageDTS", "InpatientAdmitDTS",   
  "AssignToLocationDTS", "DischargeDTS", "DepartDTS", "EstimatedDepartDTS", 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.