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
Created On |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
01/22/25 |
Timestamp |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/27/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/22/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
1/27/2025 |
Solved! Go to Solution.
Hi @ahmad1111 ,
Your Power BI DAX query was encountering errors due to the CALENDAR function, particularly when Created On was later than Timestamp, which logically should not happen since Timestamp represents proof of delivery. The calculation also needed to properly exclude weekends for certain priority levels.
The following revised DAX formula ensures that on-time delivery is calculated correctly:
OnTimeDelivery =
VAR Priority = 'Job'[Instructions]
VAR CreatedDate = 'Job'[Created On]
VAR DeliveredDate = 'Job'[Timestamp]
VAR DayPOD = FORMAT(DeliveredDate, "dddd")
VAR IsWeekend = IF(DayPOD = "Friday" || DayPOD = "Saturday", 1, 0)
VAR RawDiff = ABS(DATEDIFF(CreatedDate, DeliveredDate, DAY))
VAR AdjustedDiff =
IF(
Priority <= 3,
RawDiff - COUNTROWS(
FILTER(
ADDCOLUMNS(
CALENDAR(CreatedDate, DeliveredDate),
"WeekdayNum", WEEKDAY([Date], 2)
),
[WeekdayNum] >= 6
)
),
RawDiff
)
RETURN
IF(
(Priority <= 3 && AdjustedDiff <= 5) ||
(Priority >= 4 && RawDiff <= 1),
"OnTime",
"NotOnTime"
)
This formula first extracts the priority level, created date, and timestamp for delivery. The absolute difference in days is then calculated, and an adjustment is made for priorities 1 to 3 by excluding Fridays and Saturdays. The OnTime classification is determined based on whether the adjusted difference falls within the required threshold: for priorities 4 and 5, the delivery must be within one day (including weekends), while for priorities 1 to 3, delivery is required within five working days, excluding weekends. This ensures that the calculation correctly accounts for weekends without triggering the CALENDAR function error, preventing issues when new data is added.
Best regards,
Hi @ahmad1111
The issue you're facing stems from the logical relationship between the Created On and Timestamp fields. The ABS(DATEDIFF()) function is intended to calculate the difference between these dates, but you’re getting an error when Created On is later than Timestamp, even if the dates are the same. This could be a data quality issue that violates the assumption that Timestamp should always be later. A potential fix involves ensuring that Created On is not later than Timestamp, using ABS to avoid negative values. Additionally, simplifying the weekend logic ensures that you're correctly handling different priorities, where priority 4 and 5 deliveries allow weekends, while priorities 1-3 restrict delivery to weekdays. Finally, adjusting the difference calculation based on the priority ensures that the final measure works as expected, marking "OnTime" or "NotOnTime" without errors. Proper validation of your data and logic is key to resolving this.
Updated Measure:
calcotd =
VAR Priority = 'Job'[Instructions]
VAR Diff = ABS(DATEDIFF('Job'[Created On], 'Job'[Timestamp], DAY))
VAR DayPOD = 'Job'[PODDay]
VAR IsWeekend = IF(DayPOD = "Friday" || DayPOD = "Saturday", 1, 0)
VAR AdjustedDiff =
IF(
Priority <= 3,
Diff - COUNTROWS(
FILTER(
CALENDAR('Job'[Created On], 'Job'[Timestamp]),
WEEKDAY([Date], 2) > 5
)
),
Diff
)
RETURN
IF(
(Priority <= 3 && AdjustedDiff <= 5 && 'Job'[Late/Not] = "NotLate") ||
(Priority >= 4 && Diff <= 1 && 'Job'[Late/Not] = "NotLate"),
"OnTime",
"NotOnTime"
)
Hi @ahmad1111
The issue you're facing stems from the logical relationship between the Created On and Timestamp fields. The ABS(DATEDIFF()) function is intended to calculate the difference between these dates, but you’re getting an error when Created On is later than Timestamp, even if the dates are the same. This could be a data quality issue that violates the assumption that Timestamp should always be later. A potential fix involves ensuring that Created On is not later than Timestamp, using ABS to avoid negative values. Additionally, simplifying the weekend logic ensures that you're correctly handling different priorities, where priority 4 and 5 deliveries allow weekends, while priorities 1-3 restrict delivery to weekdays. Finally, adjusting the difference calculation based on the priority ensures that the final measure works as expected, marking "OnTime" or "NotOnTime" without errors. Proper validation of your data and logic is key to resolving this.
Updated Measure:
calcotd =
VAR Priority = 'Job'[Instructions]
VAR Diff = ABS(DATEDIFF('Job'[Created On], 'Job'[Timestamp], DAY))
VAR DayPOD = 'Job'[PODDay]
VAR IsWeekend = IF(DayPOD = "Friday" || DayPOD = "Saturday", 1, 0)
VAR AdjustedDiff =
IF(
Priority <= 3,
Diff - COUNTROWS(
FILTER(
CALENDAR('Job'[Created On], 'Job'[Timestamp]),
WEEKDAY([Date], 2) > 5
)
),
Diff
)
RETURN
IF(
(Priority <= 3 && AdjustedDiff <= 5 && 'Job'[Late/Not] = "NotLate") ||
(Priority >= 4 && Diff <= 1 && 'Job'[Late/Not] = "NotLate"),
"OnTime",
"NotOnTime"
)
Hi @ahmad1111 ,
Your Power BI DAX query was encountering errors due to the CALENDAR function, particularly when Created On was later than Timestamp, which logically should not happen since Timestamp represents proof of delivery. The calculation also needed to properly exclude weekends for certain priority levels.
The following revised DAX formula ensures that on-time delivery is calculated correctly:
OnTimeDelivery =
VAR Priority = 'Job'[Instructions]
VAR CreatedDate = 'Job'[Created On]
VAR DeliveredDate = 'Job'[Timestamp]
VAR DayPOD = FORMAT(DeliveredDate, "dddd")
VAR IsWeekend = IF(DayPOD = "Friday" || DayPOD = "Saturday", 1, 0)
VAR RawDiff = ABS(DATEDIFF(CreatedDate, DeliveredDate, DAY))
VAR AdjustedDiff =
IF(
Priority <= 3,
RawDiff - COUNTROWS(
FILTER(
ADDCOLUMNS(
CALENDAR(CreatedDate, DeliveredDate),
"WeekdayNum", WEEKDAY([Date], 2)
),
[WeekdayNum] >= 6
)
),
RawDiff
)
RETURN
IF(
(Priority <= 3 && AdjustedDiff <= 5) ||
(Priority >= 4 && RawDiff <= 1),
"OnTime",
"NotOnTime"
)
This formula first extracts the priority level, created date, and timestamp for delivery. The absolute difference in days is then calculated, and an adjustment is made for priorities 1 to 3 by excluding Fridays and Saturdays. The OnTime classification is determined based on whether the adjusted difference falls within the required threshold: for priorities 4 and 5, the delivery must be within one day (including weekends), while for priorities 1 to 3, delivery is required within five working days, excluding weekends. This ensures that the calculation correctly accounts for weekends without triggering the CALENDAR function error, preventing issues when new data is added.
Best regards,
Hi data ninja thanks for the reply ill try it now at office but see the weird part for me is i put lets say todays date 30/01/2025 for both created on and timestamp delivery date it wont accept it and that error rise up again saying created on is bigger than timestamp end date so i am confused why cant i use todays date
User | Count |
---|---|
12 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
19 | |
14 | |
10 | |
7 |