Forum Discussion
Filtering column based on a date (or another columns date)
- 3 years ago
Posting the solution myself for educational purposes:
Step 1:
First of all one needs a column for the current date:
= Table.AddColumn(#"Literal eingefügt1", "todays date", each if[Material]=null then "" else DateTime.LocalNow())
It is crucial to check if the material has no value. Otherwhise the calculation later on will proceed.
Step 2:
Change to date type + add another column:
= Table.AddColumn(#"Geänderter Typ2", "Month", each Date.Month([todays date]))
This column should take out just the month of your date - so from: 22.09.2022 The column "Month" should display just the number 9.
Step 3:
= Table.AddColumn(#"Hinzugefügte benutzerdefinierte Spalte1", "True/False", each if [Monat] >= 10 then true else if [Monat] <= 9 then false else null)
This one says that all the numbers (months in this case) greater or equal to 10 (October) are true and all the numbers (months) that are smaller or equal to 9 (September) are false.
I choose true for "consider all the materials from october"
and false for "consider not all the materials until September" (in the next step will be declared which those are)
Step 4:
= Table.SelectRows(#"Hinzugefügte bedingte Spalte", each if [#"True/False"] = false then Text.StartsWith([Material], "3") or Text.StartsWith([Material], "4") or Text.StartsWith([Material], "X") or Text.StartsWith([Material], "Y") else true)
So if the column "True/False" is false then choose just the Materials that start with 3,4,X or Y else TRUE.
You can see that the filter works as soon as you change the date or the numbers in step 3.
Please post your table with dummy data.