Forum Discussion

craigdent's avatar
craigdent
Frequent Visitor
5 years ago

Help with dates between two rows

Hi all,

 

I have a table with payroll cut off dates and would like to filter another table based on results between each cut off date. I'm not sure where to start, I've thought about creating columns to show the first and last dates of each "month" but that hasn't worked so far.

 

So for example, I'd want to select November 2020 on a slicer dropdown, and get every approved record between the 4th October and 31st October, for December is would be 1st November to 28th November, etc.

 

Is this possible?

 

Currently there is a date table which has a relationship to the Date column in the cut off table. The records I'd like to show are in another table which also has a relationship to the data table for a columns with an approved date.

 

10 Replies

  • craigdent 

    You can have two measures with Start and End dates or use these techniques with FILTER function to filter the table.

    Start Date = 
    VAR _Date = SELECTEDVALUE(Table9[Date])
    RETURN
    
    CALCULATE(
        MAX(Table9[Date]),
        FILTER(
            ALL(Table9),
            Table9[Date] < _Date
        )
    )
    End Date = 
    SELECTEDVALUE(Table9[Date])

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn






    • craigdent's avatar
      craigdent
      Frequent Visitor

      Thank you Fowmy 

       

      I've tried to use this, would Table9 be the table that stores the cut off dates in my snip? Or is this the Date table itself?

       

      I tried using that table (Overtime Deadlines) but it didn't bring anything up when I used it.

      • Fowmy's avatar
        Fowmy
        Super User

        @craigdent

        I did not take any dates table into my formula. You wanted to filter the table that you showed in the question based on the logic you mentioned. These formulas can be used to filter other tables. Why do not share a sample PBIX file with some sample data to check? Also, mention the expected result.

        ________________________

        If my answer was helpful, please consider Accept it as the solution to help the other members find it

        Click on the Thumbs-Up icon if you like this reply 🙂

        YouTube Linkedin

  • craigdent , Try like

     

    measure =
    var _Mtd = CALCULATE(Max(Table[Date]),DATESMTD('Date'[Date]))
    var _lmt = CALCULATE(Max(Table[Date]),DATESMTD(dateadd('Date'[Date],-1,MONTH))) +1

    return
    calculate([measure], filter (all('Date') , 'Date'[Date]>= _lmt && 'Date'[Date]<=_Mtd))

    • craigdent's avatar
      craigdent
      Frequent Visitor

      Thanks amitchandak,

       

      I couldn't get this working either, I think because it assumes the next monthly cut off is the same day of the next month, however it varies depending on the lenght of the month and the next pay day (which could be earlier if it would fall on a weekend or bank holiday).

       

      Also, the [measure] on the last line kept coming up with a circular error warning, should I ignore that?

      • amitchandak's avatar
        amitchandak
        Super User

        craigdent ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.