Forum Discussion
Julian-K
4 years agoRegular Visitor
Search Email Subject For Keywords, But Foldable
Hi! I want to search a mailbox (Microsoft Exchange) for mails with certain keywords in the subject. Mailbox = Exchange.Contents("[email protected]"),
Mails = Mailbox{[Name="Mail"]}[Data],
...
- 4 years ago
I'm not sure if it's possible to write the M for this so that it folds into a native Exchange query. You might need to at least download all of the Subject lines.
I'm not sure if something like this will work but it might be worth a try.
Mails = Exchange.Contents("[email protected]"){[Name="Mail"]}[Data], Keywords = List.Buffer(Keywords[Column1]), Subjects = List.Buffer(List.Distinct(Mails[Subjects])), FilteredSubjects = List.Buffer( List.Select( Subjects, (S) => List.AnyTrue( List.Transform(Keywords, each Text.Contains(S, _)) ) ) ), Filtered = Table.SelectRows(Mails, each List.Contains(FilteredSubjects, [Subject]))Note that FilteredSujects might need to be a separate query and you just use the first and last lines of the above to attempt to create a foldable query.
Julian-K
4 years agoRegular Visitor
Hey Nate,
thanks for your reply, but if I understand your code correctly, it selects mails where the subject is in the list - by comparing the entire subject to the list elements.
I don't know the entire subject beforehand. I want to select the mails where the subject contains certain keywords.
Best regards,
Julian