Forum Discussion

davet47's avatar
davet47
Regular Visitor
6 years ago
Solved

Find max date which is less than a specified date

I have a list of transactions for individual members, which has a date when each transaction occurred.  I need to find the most recent date for a member which is less than a specified date.  For exam...
  • amitchandak's avatar
    6 years ago

    Assuming slicer us coming from Date calendar


    max date =
    var _max = maxx(allselected(Date),Date[Date])
    return
    calculate(MAX('Member Financial'[Date]),'Member Financial'[Date]< _max)

    //OR

    max date =
    var _max = maxx(allselected(Date),Date[Date])
    return
    calculate(MAX('Member Financial'[Date]),filter(all('Member Financial'),'Member Financial'[Date]< _max))

    //OR With date calendar -- This one should be the way

    max date =
    var _max = maxx(allselected('Date'),'Date'[Date])
    return
    calculate(MAX('Member Financial'[Date]),filter(all('Date'),'Date'[Date]< _max))

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

     

  • v-gizhi-msft's avatar
    6 years ago

    Hi,

     

    Please try this measure to show daygap:

    DayGap = DATEDIFF(SELECTEDVALUE('Table'[Date]),SELECTEDVALUE('Date'[Date]),DAY)

    Then create a measure to calculate the most recent date:

    Most Recent Day = 
    var SummarizeTable = SUMMARIZE('Table','Table'[MemberNo],'Table'[Date],"DayGap",[DayGap])
    var FIlterTable = FILTER(SummarizeTable,[DayGap]>0)
    var MinMeasure = MINX(FIlterTable,[DayGap])
    return
    CALCULATE(MAX('Table'[Date]),FILTER(FIlterTable,[DayGap]=MinMeasure))

    The result shows:

    Here is my test pbix file:

    pbix 

    Hope this helps.

     

    Best Regards,

    Giotto Zhi