SOLVED

Power Query - Data filter

%3CLINGO-SUB%20id%3D%22lingo-sub-1744525%22%20slang%3D%22en-US%22%3EPower%20Query%20-%20Data%20filter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1744525%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20morning.%3C%2FP%3E%3CP%3EI%20hope%20there%20may%20be%20someone%20that%20can%20shed%20light%20on%20this%20problem.%3C%2FP%3E%3CP%3EI%20have%20a%20dataset%20that%20I%20have%20filters%20running%20with%20Get%20and%20Transform%20in%20Excel%20Data.%3C%2FP%3E%3CP%3EThe%20issue%20I%20have%20is%20that%20it%20is%20not%20doing%20what%20I%20am%20expecting%20it%20to%20do.%3C%2FP%3E%3CP%3EI%20have%20a%20similar%20filter%20that%20removed%20certain%20users%20from%20the%20list%20from%20a%20specific%20date%20and%20includes%20new%20users%20from%20a%20specific%20date%20without%20issue%2C%20but%20this%20one%20just%20won't%20work.%20I%20can%20filter%20out%20all%20of%20a%20CentreName%2C%20but%20that%20is%20not%20what%20I%20need%2C%20it%20should%20only%20filter%20out%20these%20names%20up%20to%20a%20specific%20date%20and%20there%20is%20another%20filter%20that%20filters%20out%20different%20names%20from%20this%20date%20forward.%20The%20date%20is%207%20September%202020.%20It%20also%20does%20not%20work.%3C%2FP%3E%3CP%3EM%20Code%3A%3C%2FP%3E%3CP%3E%3D%20Table.SelectRows(%23%22Removed%20Duplicates%22%2C%20each%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%201%20SD%22%20and%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%207%2C%200%2C%200%2C%200)%20or%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%202%20SD%22%20and%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%207%2C%200%2C%200%2C%200)%20or%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%203%20SD%22%20and%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%207%2C%200%2C%200%2C%200))%3C%2FP%3E%3CP%3EThe%20Centre%20name%20that%20must%20be%20filtered%20out%20from%20this%20date%20is%20%22Global%22%2C%20%22Enterprise%22%20and%20%22Wholesale%22%20as%20they%20are%20not%20needed%20from%20this%20date.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20in%20advance%20if%20anyone%20can%20guide%20me%20please.%20I'm%20going%20to%20keep%20looking%20in%20the%20mean%20time.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1744525%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1744802%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Query%20-%20Data%20filter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1744802%22%20slang%3D%22en-US%22%3EI%20figured%20it%20out%2C%20just%20needed%20to%20group%20my%20filters%20CentreName%20and%20ActionDateTime%20in%20brackets.%20Seems%20to%20do%20the%20trick.%3CBR%20%2F%3E%3CBR%20%2F%3E%3D%20Table.SelectRows(%23%22Removed%20Duplicates%22%2C%20each%20(%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%201%20SD%22%20and%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%207%2C%200%2C%200%2C%200))%20or%20(%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%202%20SD%22%20and%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%207%2C%200%2C%200%2C%200))%20or%20(%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%203%20SD%22%20and%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%207%2C%200%2C%200%2C%200)))%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20for%20all%20who%20had%20a%20look.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1746095%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Query%20-%20Data%20filter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1746095%22%20slang%3D%22en-US%22%3EI%20was%20actually%20trying%20this%20now%2C%20as%20my%20solution%20failed%20when%20I%20changed%20my%20source.%20Also%2C%20after%20the%20specified%20date%2C%20the%20CentreName%20%3D%203%20New%20names.%3CBR%20%2F%3ESo%20I%20need%20to%20compensate%20for%20this%20as%20the%20source%20has%20duplicated%20values%20before%20and%20after%20the%20name%20changes.%20I%20was%20able%20to%20get%20it%20to%20work%20before%2C%20but%20it%20has%20failed%20now.%20I'm%20awaiting%20the%20source%20to%20be%20fixed%2C%20but%20this%20is%20an%20interim%20solution%20which%20shouldn't%20make%20a%20difference%20once%20the%20source%20is%20fixed.%3CBR%20%2F%3EYour%20solution%20looks%20simple%2C%20but%20does%20not%20work.%20I%20did%20check%20my%20syntax.%3CBR%20%2F%3EGen%20SD1-3%20change%20names%20to%20Corporate%20SD%2C%20Enterprise%20SD%20and%20Wholesale%20SD%20at%20the%20specified%20date%20and%20time%20%23datetime(2020%2C%209%2C%207%2C%205%2C%2020%2C%200)%3CBR%20%2F%3ESo%20I%20don't%20want%20to%20see%20the%20new%20names%20before%20or%20the%20old%20names%20after.%3CBR%20%2F%3EThe%20logic%20is%20so%20simple%2C%20yet%20I%20can't%20get%20it%20to%20work.%3CBR%20%2F%3EThanks%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1746146%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Query%20-%20Data%20filter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1746146%22%20slang%3D%22en-US%22%3EI'm%20trying%20this%20now%20as%20an%20alternative%20as%20it%20has%20filtered%20out%20all%20my%20data.%3CBR%20%2F%3E%3D%20Table.SelectRows(%23%22Extracted%20Date%22%2C%20each%20%5BActionDateTime%5D%20%26lt%3B%20%23datetime(2020%2C%209%2C%205%2C%2020%2C%200%2C%200)%20and%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%20SD1%22%20and%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%20SD2%22%20and%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Gen%20SD3%22%20or%20%5BActionDateTime%5D%20%26gt%3B%3D%20%23datetime(2020%2C%209%2C%205%2C%2020%2C%200%2C%200)%20and%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Corporate%22%20and%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Enterprise%22%20and%20%5BCentreName%5D%20%26lt%3B%26gt%3B%20%22Wholesale%22)%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Good morning.

I hope there may be someone that can shed light on this problem.

I have a dataset that I have filters running with Get and Transform in Excel Data.

The issue I have is that it is not doing what I am expecting it to do.

I have a similar filter that removed certain users from the list from a specific date and includes new users from a specific date without issue, but this one just won't work. I can filter out all of a CentreName, but that is not what I need, it should only filter out these names up to a specific date and there is another filter that filters out different names from this date forward. The date is 7 September 2020. It also does not work.

M Code:

= Table.SelectRows(#"Removed Duplicates", each [CentreName] <> "Gen 1 SD" and [ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0) or [CentreName] <> "Gen 2 SD" and [ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0) or [CentreName] <> "Gen 3 SD" and [ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0))

The Centre name that must be filtered out from this date is "Global", "Enterprise" and "Wholesale" as they are not needed from this date.

 

Thank you in advance if anyone can guide me please. I'm going to keep looking in the mean time.

7 Replies
Highlighted
I figured it out, just needed to group my filters CentreName and ActionDateTime in brackets. Seems to do the trick.

= Table.SelectRows(#"Removed Duplicates", each ([CentreName] <> "Gen 1 SD" and [ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0)) or ([CentreName] <> "Gen 2 SD" and [ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0)) or ([CentreName] <> "Gen 3 SD" and [ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0)))

Thanks for all who had a look.
Highlighted

@Shaun99 

I guess you may simplify a bit

 

= Table.SelectRows(
   #"Removed Duplicates",
   each
      ([ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0)) and
      (
         ([CentreName] <> "Gen 1 SD")  or
         ([CentreName] <> "Gen 2 SD")  or
         ([CentreName] <> "Gen 3 SD")
      )
)

 

Corrected one:

= Table.SelectRows(
   #"Removed Duplicates",
   each
      ([ActionDateTime] < #datetime(2020, 9, 7, 0, 0, 0)) and
      (
         ([CentreName] <> "Gen 1 SD")  and
         ([CentreName] <> "Gen 2 SD")  and
         ([CentreName] <> "Gen 3 SD")
      )
)

 

Highlighted
I was actually trying this now, as my solution failed when I changed my source. Also, after the specified date, the CentreName = 3 New names.
So I need to compensate for this as the source has duplicated values before and after the name changes. I was able to get it to work before, but it has failed now. I'm awaiting the source to be fixed, but this is an interim solution which shouldn't make a difference once the source is fixed.
Your solution looks simple, but does not work. I did check my syntax.
Gen SD1-3 change names to Corporate SD, Enterprise SD and Wholesale SD at the specified date and time #datetime(2020, 9, 7, 5, 20, 0)
So I don't want to see the new names before or the old names after.
The logic is so simple, yet I can't get it to work.
Thanks
Highlighted
I'm trying this now as an alternative as it has filtered out all my data.
= Table.SelectRows(#"Extracted Date", each [ActionDateTime] < #datetime(2020, 9, 5, 20, 0, 0) and [CentreName] <> "Gen SD1" and [CentreName] <> "Gen SD2" and [CentreName] <> "Gen SD3" or [ActionDateTime] >= #datetime(2020, 9, 5, 20, 0, 0) and [CentreName] <> "Corporate" and [CentreName] <> "Enterprise" and [CentreName] <> "Wholesale")
Highlighted

@Shaun99 

You are right, sorry for the mistake, it shall be and in formula, not or

Highlighted

@Sergei Baklan Thank you for the tip. Had to figure out the date filtering order otherwise the records would be missing to filter on. I got it to work, and yes had to use date "and" and <> center "or" <> center.
I use a similar filter where staff have been reshuffled.

Ultimately it would be better to do this server side, but for now this is what I have to work with as I am given a flat file.

Thank you.

Highlighted
Best Response confirmed by Shaun99 (Occasional Contributor)
Solution

@Sergei Baklan 

This is what I have used, and works from what I can see.
= Table.SelectRows(#"Extracted Date", each [ActionDateTime] < #datetime(2020, 9, 5, 20, 0, 0) and [CentreName] <> "Gen SD1" and [CentreName] <> "Gen SD2" and [CentreName] <> "Gen SD3" or [ActionDateTime] >= #datetime(2020, 9, 5, 20, 0, 0) and [CentreName] <> "Corporate" and [CentreName] <> "Enterprise" and [CentreName] <> "Wholesale")