Forum Discussion
Catagorize by date range
- 5 years ago
Hi AGhyst
From the screenshot, the date columns are already of date type, so you don't need to use Date.From() function in the code. For example,
if [Tariff_Category] = "NONE" or [Tariff_Category] = "EU_SKU" or [TariffDate_Created] < #date(2018,11,1) then "NONE" else if [Tariff_Category] = "TURBO" then "TURBO-21.1%" else if [Tariff_Category] = "OTHER" or [Tariff_Category] = "CREDIT" and [TariffDate_Created] >= [T1_Imp_OTHER] and [TariffDate_Created] < [T2_Imp_OTHER] then "OTHER-8.4%" else "REVIEW"In addition, there seems to be some logical errors in your current codes. For example in below part, it automatically generates conditions' priority order like below (I add parentheses to make it clearer) because And has a higher priority than Or. When a Tariff_Category is OTHER, it will always return the result "OTHER-8.4%".
So it is suggested to use parentheses to wrap conditions which should have higher priorities. This would make codes easier to understand.
Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.
Hi AGhyst
From the screenshot, the date columns are already of date type, so you don't need to use Date.From() function in the code. For example,
if [Tariff_Category] = "NONE"
or [Tariff_Category] = "EU_SKU"
or [TariffDate_Created] < #date(2018,11,1)
then "NONE"
else if [Tariff_Category] = "TURBO"
then "TURBO-21.1%"
else if [Tariff_Category] = "OTHER"
or [Tariff_Category] = "CREDIT"
and [TariffDate_Created] >= [T1_Imp_OTHER]
and [TariffDate_Created] < [T2_Imp_OTHER]
then "OTHER-8.4%"
else "REVIEW"
In addition, there seems to be some logical errors in your current codes. For example in below part, it automatically generates conditions' priority order like below (I add parentheses to make it clearer) because And has a higher priority than Or. When a Tariff_Category is OTHER, it will always return the result "OTHER-8.4%".
So it is suggested to use parentheses to wrap conditions which should have higher priorities. This would make codes easier to understand.
Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.
- AGhyst5 years agoFrequent Visitor
Thank you for explaining that AND has priority over OR. That not only help me with this report but with a similar problem in a Tableau report I'm running!