Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
Hi, I have deliveries table, that are for multiple customers and have PGI and Delivery dates.
I created calculated column that counts difference between PGI and Delivery date.
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
Solved! Go to Solution.
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
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.
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
User | Count |
---|---|
67 | |
61 | |
47 | |
33 | |
32 |
User | Count |
---|---|
87 | |
72 | |
56 | |
49 | |
45 |