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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
tkavitha911
Helper III
Helper III

urgent help needed

This is the daily data at the port, but since the dates are not continuous, I created a separate dates table. I need help writing a DAX measure to calculate the difference between the Max ETA Date and the Predicted Delivery Date for each market. If the difference exceeds the capacity, the delivery should be scheduled for the next day.

The expression will be: (Max ETA Date - Predicted Delivery Date). If the difference exceeds the available capacity, the remaining quantity should be carried over to the next day, and this cycle should continue until all deliveries are scheduled.


MarketMax of etaPredicted_Delivery_DateMax of etaCapacity
Japan01-02-2024'04-01-190012-10-20242
Japan01-02-2024'04-01-190010-03-20252
Philippines01-02-2024'04-01-190010-04-20259
Vietnam01-02-2024'04-01-190004-10-20242
Taiwan01-02-2024'04-01-190019-04-20256
Thailand01-02-2024'04-01-190001-03-20257
Australia01-02-2024'04-01-190008-02-20256
China01-02-2024'04-01-190030-03-20258
Shenzhen01-02-2024'04-01-190023-03-20254
Korea01-02-2024'04-01-190029-11-202410
Vietnam01-02-2024'04-01-190021-03-20252
China01-02-2024'04-01-190021-03-20258
Japan02-02-202404-01-190021-03-20252
Japan03-02-202404-01-190021-03-20252
Philippines04-02-202404-01-190021-03-20259
Vietnam05-02-202404-01-190021-03-20252
Taiwan02-02-202404-01-190004-04-20256
Thailand03-02-202404-01-190004-04-20257
Australia04-02-202404-01-190004-04-20256
China05-02-202404-01-190030-03-20258
Shenzhen06-02-202404-01-190004-04-20254
Korea07-02-202404-01-190003-05-202510
Vietnam08-02-202404-01-190021-08-20242
China09-02-202404-01-190021-08-20248
1 ACCEPTED SOLUTION
v-csrikanth
Community Support
Community Support

Hi @tkavitha911 
Thank you for being part of the Microsoft Fabric Community.

 

  1. The scenario involves distributing delivery quantities from the Predicted Delivery Date to the Max ETA Date, constrained by a daily Capacity per market.

  2. If the total quantity to be delivered exceeds the daily capacity, the remaining quantity should be scheduled on subsequent available dates, even beyond the Max ETA if needed.

  3. A separate Dates table is necessary to handle non-continuous date ranges and to ensure date-based calculations work properly.

  4. The solution uses a calculated table in Power BI to simulate this delivery schedule. It:

    • Calculates total quantity using the date difference between Max ETA and Predicted Delivery Date.

    • Determines the number of days required to complete the delivery based on capacity.

    • Uses GENERATESERIES and RANKX on the Dates table to assign deliveries to actual dates.

    • Carries forward the remaining quantity to the next valid delivery date from the Dates table.

  5. Here's the DAX for the calculated table:

    DeliverySchedule =
    VAR BaseTable =
    ADDCOLUMNS (
    'YourDataTable',
    "StartDate", [Predicted_Delivery_Date],
    "EndDate", [Max of eta],
    "TotalQty", DATEDIFF([Predicted_Delivery_Date], [Max of eta], DAY) + 1
    )

    RETURN
    GENERATE (
    BaseTable,
    VAR TotalQty = [TotalQty]
    VAR Capacity = [Capacity]
    VAR StartDate = [StartDate]
    VAR NumDays = CEILING (TotalQty / Capacity, 1)
    RETURN
    ADDCOLUMNS (
    GENERATESERIES (0, NumDays - 1, 1),
    "DeliveryDate",
    CALCULATE (
    MIN ( 'Dates'[Date] ),
    FILTER (
    'Dates',
    'Dates'[Date] >= StartDate &&
    RANKX (
    FILTER ( 'Dates', 'Dates'[Date] >= StartDate ),
    'Dates'[Date],
    ,
    ASC
    ) = [Value] + 1
    )
    ),
    "DeliveredQty",
    VAR Remaining = TotalQty - [Value] * Capacity
    RETURN IF (Remaining >= Capacity, Capacity, Remaining)
    )
    )

  6. This table can now be used in your visuals (e.g., Gantt charts or line graphs) to display delivery progress over time per market.

  7. The logic ensures that delivery respects the capacity and date availability, even if the deliveries need to go past the Max ETA Date.


If the above information helps you, please give us a Kudos and marked the Accept as a solution.
Best Regards,
Community Support Team _ C Srikanth.

 

View solution in original post

5 REPLIES 5
v-csrikanth
Community Support
Community Support

Hi @tkavitha911 

We haven't heard from you since last response and just wanted to check whether the solution provided has worked for you. If yes, please Accept as Solution to help others benefit in the community.
Thank you.

If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth.

v-csrikanth
Community Support
Community Support

HI @tkavitha911 
It's been a while since I heard back from you and I wanted to follow up. Have you had a chance to try the solutions that have been offered?
If the issue has been resolved, can you mark the post as resolved? If you're still experiencing challenges, please feel free to let us know and we'll be happy to continue to help!
Looking forward to your reply!

If the above information helps you, please give us a Kudos and marked the Accept as a solution.

Best Regards,
Community Support Team _ C Srikanth.

v-csrikanth
Community Support
Community Support

Hi @tkavitha911 

I wanted to follow up since I haven't heard from you in a while. Have you had a chance to try the suggested solutions?
If your issue is resolved, please consider marking the post as solved. However, if you're still facing challenges, feel free to share the details, and we'll be happy to assist you further.
Looking forward to your response!

Best Regards,
Community Support Team _ C Srikanth.

v-csrikanth
Community Support
Community Support

Hi @tkavitha911 
Thank you for being part of the Microsoft Fabric Community.

 

  1. The scenario involves distributing delivery quantities from the Predicted Delivery Date to the Max ETA Date, constrained by a daily Capacity per market.

  2. If the total quantity to be delivered exceeds the daily capacity, the remaining quantity should be scheduled on subsequent available dates, even beyond the Max ETA if needed.

  3. A separate Dates table is necessary to handle non-continuous date ranges and to ensure date-based calculations work properly.

  4. The solution uses a calculated table in Power BI to simulate this delivery schedule. It:

    • Calculates total quantity using the date difference between Max ETA and Predicted Delivery Date.

    • Determines the number of days required to complete the delivery based on capacity.

    • Uses GENERATESERIES and RANKX on the Dates table to assign deliveries to actual dates.

    • Carries forward the remaining quantity to the next valid delivery date from the Dates table.

  5. Here's the DAX for the calculated table:

    DeliverySchedule =
    VAR BaseTable =
    ADDCOLUMNS (
    'YourDataTable',
    "StartDate", [Predicted_Delivery_Date],
    "EndDate", [Max of eta],
    "TotalQty", DATEDIFF([Predicted_Delivery_Date], [Max of eta], DAY) + 1
    )

    RETURN
    GENERATE (
    BaseTable,
    VAR TotalQty = [TotalQty]
    VAR Capacity = [Capacity]
    VAR StartDate = [StartDate]
    VAR NumDays = CEILING (TotalQty / Capacity, 1)
    RETURN
    ADDCOLUMNS (
    GENERATESERIES (0, NumDays - 1, 1),
    "DeliveryDate",
    CALCULATE (
    MIN ( 'Dates'[Date] ),
    FILTER (
    'Dates',
    'Dates'[Date] >= StartDate &&
    RANKX (
    FILTER ( 'Dates', 'Dates'[Date] >= StartDate ),
    'Dates'[Date],
    ,
    ASC
    ) = [Value] + 1
    )
    ),
    "DeliveredQty",
    VAR Remaining = TotalQty - [Value] * Capacity
    RETURN IF (Remaining >= Capacity, Capacity, Remaining)
    )
    )

  6. This table can now be used in your visuals (e.g., Gantt charts or line graphs) to display delivery progress over time per market.

  7. The logic ensures that delivery respects the capacity and date availability, even if the deliveries need to go past the Max ETA Date.


If the above information helps you, please give us a Kudos and marked the Accept as a solution.
Best Regards,
Community Support Team _ C Srikanth.

 

bhanu_gautam
Super User
Super User

@tkavitha911 , Try using

dax
DeliverySchedule =
VAR MaxETADate = MAX('Table'[Max of eta])
VAR PredictedDeliveryDate = MAX('Table'[Predicted_Delivery_Date])
VAR Capacity = MAX('Table'[Capacity])
VAR DateDifference = DATEDIFF(PredictedDeliveryDate, MaxETADate, DAY)
VAR RemainingQuantity = DateDifference - Capacity

RETURN
IF(
DateDifference <= Capacity,
DateDifference,
RemainingQuantity
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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