Forum Discussion
Need help dax measure
- 1 year ago
Hi tkavitha911 have done this using m code, please take a look. Here the daily container capacity is set to 2 for example
In the advanced editor, add this
#"Added Daysused" = Table.AddColumn(#"Changed Type", "Daysused", each Duration.Days([PredictedDelivery] - [ETA])),
#"Added Overdue Flag" = Table.AddColumn(#"Added Daysused", "Overdue flag", each [Daysused] > [FreeDays]),
DailyCounts = Table.Group(#"Added Overdue Flag", {"PredictedDelivery"}, {
{"ContainerList", each _, type table [
Plant=nullable text,
Container Number=nullable text,
ETA=nullable date,
PredictedDelivery=nullable date,
FreeDays=nullable number,
Daysused=nullable number,
Overdue flag=nullable logical
]},
{"DailyCount", each Table.RowCount(_), Int64.Type}
}),Sorted = Table.Sort(DailyCounts, {"PredictedDelivery", Order.Ascending}),
DailyCapacity = 2,
RowCount = Table.RowCount(Sorted),ResultList = List.Generate(
() => [i = 0, carry = 0, list = {}],
each [i] < RowCount,
each [
row = Sorted{i},
date = row[PredictedDelivery],
count = row[DailyCount],
containerList = row[ContainerList],
totalToday = count + [carry],
processed = if totalToday <= DailyCapacity then totalToday else DailyCapacity,
newCarry = if totalToday > DailyCapacity then totalToday - DailyCapacity else 0,
newRow = [
PredictedDelivery = date,
ContainerList = containerList,
DailyCount = count,
AdjustedCount = processed,
CarryForward = newCarry
],
list = [list] & {newRow},
i = [i] + 1,
carry = newCarry
]
),CarryForwardTable = Table.FromRecords(ResultList{List.Count(ResultList)-1}[list])
in
CarryForwardTable - Anonymous1 year ago
Hi tkavitha911,
To calculate whether the predicted delivery is delayed beyond the allowed free days, you can create a calculated column (or a measure, depending on your visual/reporting needs) using the following DAX:
Delay Beyond Free Days =
VAR DelayDays = DATEDIFF('Table'[Max of ETA], 'Table'[Predicted_Delivery_Date], DAY)
RETURN
IF(DelayDays > 'Table'[FT DAYS], DelayDays, BLANK())For handling overflow based on daily capacity part, we’d need to simulate the logic where containers are processed based on a daily capacity limit, and any overflow is carried over to the next day.
This kind of logic is difficult to implement with DAX alone, since DAX is not well-suited for row-wise iterative logic with carryovers. Instead, I recommend using Power Query (M language) for this step.
Here’s a high-level outline of how you could implement it in Power Query:
-
Group containers by date (Predicted Delivery Date).
-
Sort dates in ascending order.
-
Define a parameter for daily capacity (e.g., 5 containers per day).
-
Use a loop or custom column logic to:
-
Check if the container count on a given date exceeds the capacity.
-
If it does, carry the excess forward and add it to the next date’s count.
-
Continue this iteratively for all dates.
-
This might involve writing a custom function or using a running total approach to track the overflow.
Best Regards,
Hammad.
-
Hi tkavitha911,
Thanks for reaching out to the Microsoft fabric community forum.
It looks like you want a DAX to calculate the difference between the Predicted Delivery Date and the Maximum ETA Date and based on certain conditions(Exceeding free days) it should return the number of days or else, it should return a blank. As Poojara_D12, FreemanZ, maruthisp and bhanu_gautam all responded to your query, please go through the solution provided by them and check if it solves your query.
Also mark the helpful reply as solution so that other community members can find the solution easily.
I would also take a moment to thank Poojara_D12, FreemanZ, maruthisp and bhanu_gautam for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Best Regards,
Hammad.
Community Support Team
If this post helps then please mark it as a solution, so that other members find it more quickly.
Thank you.
- Anonymous1 year agoNot applicable
Hi tkavitha911,
As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.
If yes, you are welcome to share your workaround and mark it as a solution so that other users can benefit as well. If you find a reply particularly helpful to you, you can also mark it as a solution.
If you still have any questions or need more support, please feel free to let us know. We are more than happy to continue to help you.
Thank you for your patience and look forward to hearing from you.