Forum Discussion

nielsvanbruggen's avatar
nielsvanbruggen
Regular Visitor
8 years ago

Filter rows where difference between dates is lower than 31 days

Hello,

 

have a dataset where I want to filter out (or combine) rows when the difference between the enddate of this row and the startdate of another row is lower than 31 days.

 

The dataset looks something like this (the last columns show what I would like to accomplish):

 

 

ClientIDProductIDStartdateEnddate StartDate(What I want)Enddate (What I want)
1231  1-1-17 28-2-17 1-1-17 30-6-17
231  1-3-1731-5-17 1-1-1730-6-17
231  1-6-1730-6-171-1-1730-6-17
231 1-9-1730-10-171-9-17 31-12-17
231  1-11-1731-12-171-9-17 31-12-17
231  1-1-18 1-9-1731-12-17
      
      

 

In Excel this is quite easy, but I don't know how to accomplish it in Power BI.

 

Can someone help me?


Thanks!! 

7 Replies

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi nielsvanbruggen,

     

    "filter out (or combine) rows when the difference between the enddate of this row and the startdate of another row is lower than 31 days."

     

    What does startdate of another row mean? How do determine which startdate is used to compare with enddate in current row?

     

    What is your desired output? Do you want a new table which has been filtered? Or do you want to add a new calculated column in source table?

     

    Please provide more description about [StartDate(What I want)] and [Enddate(what I want)]. I don't understand how to get values like this.

     

    Best regards,

    Yuliana Gu

  • Anonymous's avatar
    Anonymous
    Not applicable

    Dear nielsvanbruggen,

     

    You can create a new column, using this formular:

    • StartDate(What you want) = MIN (Table[Startdate], ALLEXCEPT(Table, ClientID))
    • EndDate(What you want) = MAX(Table[Enddate], ALLEXCEPT(Table, ClientID))

     

    And all the same ClientID will have same min startDate and max Endate.

     

    Rregards,

    ManNVSM.

    • nielsvanbruggen's avatar
      nielsvanbruggen
      Regular Visitor

      Thanks for all the reactions!

       

      I did create new columns with the DAX-formulas you presented. The problem is that when the enddate in one row is more than 31 days before the startdate of the next row, I want the formula to keep the startdate of that row and use it for the rows to come (for the combination clientid and product. 

       

      Is this clear enough? I hope so! :)

      • Anonymous's avatar
        Anonymous
        Not applicable

         

        nielsvanbruggen

        Can you copy your formular in your excel please?

         

        Regards,

        ManNVSM.