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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Justas4478
Post Prodigy
Post Prodigy

IF statement calculated column

Hi, I have deliveries table, that are for multiple customers and have PGI and Delivery dates.

Justas4478_0-1732018059726.png

I created calculated column that counts difference between PGI and Delivery date.

Order Day diffrence = DATEDIFF('Store Order data'[PGI date],'Store Order data'[Delivery Date],DAY)


At the moment calculated shows all days.
I need to create another calculated column that has some IF logic since there is expected minimum number of days before delivery and it differs from customer to customer as well there are additional logic if PGI date is Thursday or Friday.
I will try to explain the best I can and provide data sample as well.
I will use this creenshot as reference for my explanation.

If 'Customer' is "Stores UK","Aldi","Matalan","Online","Sandpiper","TRS" -2 from 'Order Day difference' , but if PGI date is Thursday then -3 on top of -2(Total -5), if Friday then -2 on top of -2(Total -4),
If 'Customer' is "Stores NI" -3 from 'Order Day difference' , but if PGI date is Thursday then -3 on top of -3(Total -6), if Friday then -2 on top of -3(Total -5),
If 'Customer' is "Stores ROI" -5 from 'Order Day difference' , but if PGI date is Thursday then -3 on top of -5(Total -8), if Friday then -2 on top of -5(Total -7)

As you see logic for if PGI date is Thursday or Friday is the same across all customers, but what can be different is minimum number of days that needs to wait.
Some other customers might use same as Stores UK minimum number of days then they can be grouped together.

The problem is I am not really good with if statments and this one seams like a complex one.

If there is something that is unclear please let me know and I will try to explain better.
Here is sample file: https://we.tl/t-qBvHNpVFJ0 

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @Justas4478 ,

I recommend you to use SWITCH function instead of if statement.
Please try the bellow DAX code:

Order Day Adjustment = 
VAR Customer = 'Store Order data'[Customer]
VAR PGIDate = 'Store Order data'[PGI date]
VAR OrderDayDiff = 'Store Order data'[Order Day difference]
VAR BaseAdjustment = 
    SWITCH(
        TRUE(),
        Customer IN {"Stores UK", "Aldi", "Matalan", "Online", "Sandpiper", "TRS"}, -2,
        Customer = "Stores NI", -3,
        Customer = "Stores ROI", -5,
        0
    )
VAR AdditionalAdjustment = 
    SWITCH(
        TRUE(),
        WEEKDAY(PGIDate, 2) = 4, -3,  // Thursday
        WEEKDAY(PGIDate, 2) = 5, -2,  // Friday
        0
    )
RETURN
    OrderDayDiff + BaseAdjustment + AdditionalAdjustment

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi  @Justas4478 ,

 

Is your problem solved, if so, you can mark it as correct, if not, provide more detailed information and we can help you better!

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Bibiano_Geraldo
Super User
Super User

Hi @Justas4478 ,

I recommend you to use SWITCH function instead of if statement.
Please try the bellow DAX code:

Order Day Adjustment = 
VAR Customer = 'Store Order data'[Customer]
VAR PGIDate = 'Store Order data'[PGI date]
VAR OrderDayDiff = 'Store Order data'[Order Day difference]
VAR BaseAdjustment = 
    SWITCH(
        TRUE(),
        Customer IN {"Stores UK", "Aldi", "Matalan", "Online", "Sandpiper", "TRS"}, -2,
        Customer = "Stores NI", -3,
        Customer = "Stores ROI", -5,
        0
    )
VAR AdditionalAdjustment = 
    SWITCH(
        TRUE(),
        WEEKDAY(PGIDate, 2) = 4, -3,  // Thursday
        WEEKDAY(PGIDate, 2) = 5, -2,  // Friday
        0
    )
RETURN
    OrderDayDiff + BaseAdjustment + AdditionalAdjustment

@Bibiano_Geraldo Thanks for the response.
It looks to be working at first glance, but I need to check results before accepting as solution.

Cool, any problem don't hesitate to touch me

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.