-1

I'm trying to filter values in my table based on a date field in Power Query Editor. The dates that need to be included are dependent on a second column, indicatorCode. I've tried the code below but can't get it to work. Is this possible and if so, how?

= Table.SelectRows(Source,((each [EndDate] < #date(2023, 7, 1) and [IndicatorCode] = "CDBR:137"), (each [EndDate] < #date(2023, 8, 1) and [IndicatorCode] <> "CDBR:137")))
regents
  • 600
  • 6
  • 15

1 Answers1

-1

This answer is more about the troubleshooting process rather than the correct formula.

  • double check that the dates are actually dates
  • Put the filter conditions into new columns, use an If statement and return true/false or a text flag.
  • Work on one condition set at a time until you get the result you need. You would now have two helpler columns
  • Combine the two condition statements into one, until you have the result you want.
  • You can then apply the logic to the first step, however, sometimes it's a lot easier to maintain Power Query code when you do it one step at a time.

For complex filtering, I often create helper columns with the conditions, then filter on the helper column. After that, I remove the helper column. There is no big benefit in doing it all in one incomprehensible statement, since the data is already loaded into the query.

teylyn
  • 34,374
  • 4
  • 53
  • 73