Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Find the most recent date

Hi all!

I'm very new to Power BI and Dax calculations.  I know this is likely very simple! The examples I'm finding are more complex than I need and are confusing me more than helping.  I'm have two data sources, one is a Reference table of dates (Payment Cycles), the other a list of outgoing payments (Payments).  I need to find the date from the Payment table cycle table that is closest to the date in the Payment Cycle table, but is not after it.    

 

Here's a sample of my data:

 

 

Thank you so much for any tips!

10 Replies

  • ValtteriN's avatar
    ValtteriN
    Community Champion

    Hi,

    Here is one way to do this:

    Example data:

     

    Dax:

    LatestDate =
    var Cdate = SELECTEDVALUE(DateToLook[DateToLook]) return

    CALCULATE(MAX(DateToGet[DateToGet]),ALL(DateToGet[DateToGet]),DateToGet[DateToGet]<Cdate)

    End result:

     


    I hope this helps and if it does consider accepting this as a solution and liking the post!
  • smpa01's avatar
    smpa01
    Community Champion

    Anonymous  provide sample data and expected output,betetr still provide a sample pbix. uplaod in 1/g drive and share the link here.

  • smpa01's avatar
    smpa01
    Community Champion

    Anonymous  just so I understand, you want to bring the closest 

     

    Payments[Due Date]

     

    to the following table?

     

    PaycycleDates 

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      @smpa01 Yes that's correct!

      • smpa01's avatar
        smpa01
        Community Champion

        Anonymous  you can use this emasure

        Measure = 
        var _max = MAX(PaycycleDates[Payday])
        var _val = CALCULATE(MAX(Payments[Due Date]),FILTER(Payments,Payments[Due Date]<=_max))
        return _val