Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
AGhyst
Frequent Visitor

Catagorize by date range

Hi Everyone. 

 

This is making me crazy and I'm sure it is simple but I can't see it.  I have to put every invoice into a category of tariff based on the date of the invoice/credit. 

I've done this several ways but can't get it working right and I don't think it would work in DAX because it needs to run through 3M+ rows.

 

AGhyst_0-1626037402767.png

 

This is my most recent rendition

if [Tariff_Category]="NONE"
or [Tariff_Category]="EU_SKU"
or Date.From[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 Date.From[TariffDate_Created] >= Date.From[T1_Imp_OTHER]
and Date.From[TariffDate_Created] < Date.From[T2_Imp_OTHER]
then "OTHER-8.4%"

else if [Tariff_Category]="OTHER"
or [Tariff_Category] = "CREDIT"
and Date.From[TariffDate_Created] >=Date.From[T2_Imp_OTHER]
then "OTHER-21.1%"

else if [Tariff_Category]="AXLE"
and Date.From[TariffDate_Created] >=Date.From[T2_Rem_AXLE]
and Date.From[TariffDate_Created] < Date.From[T2_ReImp_AXLE]
then "NONE-EXEMPT"

else if [Tariff_Category]="AXLE"
and Date.From[TariffDate_Created] >=Date.From[T2_Imp_AXLE]
and Date.From[TariffDate_Created] < Date.From[T2_Rem_AXLE]
then "AXLE-21.1%"

else if [Tariff_Category]="AXLE"
and Date.From[TariffDate_Created] >=Date.From[T1_Imp_AXLE]
and Date.From[TariffDate_Created] < Date.From[T2_Imp_AXLE]
then "AXLE-8.4%"

else if [Tariff_Category]="AXLE"
and Date.From[TariffDate_Created] >=Date.From[T2_ReImp_AXLE]
then "AXLE-21.1%"

else "Review"

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

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"

071406.jpg

 

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%". 071407.jpg

 

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.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @AGhyst 

 

Does my solution make sense? Have you solved this problem?

 

Regards,
Community Support Team _ Jing

v-jingzhang
Community Support
Community Support

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"

071406.jpg

 

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%". 071407.jpg

 

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.

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!

Anonymous
Not applicable

Your functions should be followed by parentheses, like:

 

Date.From(TariffDate_Created])

Other than that, just make sure that your it/and/else statements are logically structured, and when in doubt, use parentheses.

 

--Nate

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.