Remove row if difference between two dates is greater than 7 months

  • Hi

    I'm importing data from another report that I drop into a PowerQuery folder source.

    I have two columns showing a start date and an end date.

    I would like to add a third column showing the numeric difference in months between the two dates to a max value of six months (plus days). Anything that is equal to or greater than seven months can be discarded.

    I've tried adding a conditional column but can't see how to implement an IF / THEN type condition that allows me to calculate the date difference and remove the row if the condition is met.


    I can do this after the table has been produced by PQ using DateDif, applying a filter then deleting the unwanted rows manually - but ideally I'd like to do this as part of the import process.


    Anyone know if this is possible?

  • Hi,


    If your question is related to designing the formula, you can test :


    =yourSecondDate>=EDATE(yourFirstDate,7)


    Hope this will help :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi Karim

    it would seem EDATE doesn't exist in Power Query. When constructing a custom column and adding the formula above I get an expression error that EDATE isn't recognised. There is no EDATE field to choose when building the expression.

    = Table.AddColumn(#"Changed Type", "Custom", each [Finish]>=EDATE([Start],7))


    However, EDATE does exist if I type it in directly into an excel cell.

  • My understanding was that you wanted to add your column, your calculation, filter your records out ...BEFOREHAND ... during your initial process before using Power Query ...


    Is it the case or not ?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi Karim


    No, I'm trying to delete the rows within the power query query process.

    If PQ can do it as part of the transform and load process then it saves me having to mess about with the file before or after PQ has done it's job.

  • Well ... as an initial remark handling dates in Power Query can be extremely tricky ...

    see following link :

    Power Query date format (How to + 5 tricky scenarios)
    In this post we look at the basics of Power Query date formats. Then look at some tricky date format scenarios.
    exceloffthegrid.com


    In addition, the equivalent of Datediff in PQ is not exactly obvious ...

    see following link:

    How to use Datediff in power query
    I want to create a conditional or a custom column within Power Query (using M) and NOT DAX, Here is my requirement   if [Consent Application Submitted] is not…
    community.powerbi.com

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Date.AddMonths should work the same way as EDATE

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Apologies for late response - I've been away for a couple of weeks.

    Thanks for the responses. I'll get round to looking at them once I've got round to doing everything else my boss wants doing ;)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!