Forum Discussion
Dax formula not working
- Anonymous2 years ago
Hi, teffita
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2. Below are the measure I've created for your needs:
DaysLate_Express = VAR CreatedTime = MAX(Orders[AdjustedTime]) VAR FulfilledTime = MAX(Orders[Fulfilment Date Adjusted]) VAR CreatedDateOnly = DATEVALUE(CreatedTime) VAR FulfilledDateOnly = DATEVALUE(FulfilledTime) VAR CreatedDay = WEEKDAY(CreatedDateOnly, 2) VAR IsAfter8PM = IF(HOUR(CreatedTime) >= 20, 1, 0) VAR AdjustedCreatedDate = SWITCH( TRUE(), IsAfter8PM = 1 && CreatedDay = 6, CreatedDateOnly + 2, IsAfter8PM = 1 && CreatedDay = 7, CreatedDateOnly + 1, IsAfter8PM = 1, CreatedDateOnly + 1, CreatedDateOnly ) VAR DaysLate = IF( FulfilledDateOnly > AdjustedCreatedDate, DATEDIFF(AdjustedCreatedDate, FulfilledDateOnly, DAY) - COUNTROWS( FILTER( {1, 2, 3, 4, 5, 6, 7}, [Value] = 7 && [Value] >= WEEKDAY(AdjustedCreatedDate, 2) && [Value] <= WEEKDAY(FulfilledDateOnly, 2) ) ), 0 ) RETURN IF(DaysLate > 0, DaysLate, 0)3.Here's my final result, which I hope meets your requirements.
Please find the attached pbix relevant to the case.
Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, teffita
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2. Below are the measure I've created for your needs:
DaysLate_Express =
VAR CreatedTime = MAX(Orders[AdjustedTime])
VAR FulfilledTime = MAX(Orders[Fulfilment Date Adjusted])
VAR CreatedDateOnly = DATEVALUE(CreatedTime)
VAR FulfilledDateOnly = DATEVALUE(FulfilledTime)
VAR CreatedDay = WEEKDAY(CreatedDateOnly, 2)
VAR IsAfter8PM = IF(HOUR(CreatedTime) >= 20, 1, 0)
VAR AdjustedCreatedDate =
SWITCH(
TRUE(),
IsAfter8PM = 1 && CreatedDay = 6, CreatedDateOnly + 2,
IsAfter8PM = 1 && CreatedDay = 7, CreatedDateOnly + 1,
IsAfter8PM = 1, CreatedDateOnly + 1,
CreatedDateOnly
)
VAR DaysLate =
IF(
FulfilledDateOnly > AdjustedCreatedDate,
DATEDIFF(AdjustedCreatedDate, FulfilledDateOnly, DAY) -
COUNTROWS(
FILTER(
{1, 2, 3, 4, 5, 6, 7},
[Value] = 7 && [Value] >= WEEKDAY(AdjustedCreatedDate, 2) && [Value] <= WEEKDAY(FulfilledDateOnly, 2)
)
),
0
)
RETURN
IF(DaysLate > 0, DaysLate, 0)
3.Here's my final result, which I hope meets your requirements.
Please find the attached pbix relevant to the case.
Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.