r/ExcelPowerQuery • • Jul 08 '25

I really need help with this Power Query...

Hi all

(I’ve whitened out some data as this is company sensitive)

So, the issue i have is that i need to create a ‘simple’ planning on what day we can earliest receive containers at our company with the only rule that we can only receive 15 containers each day.

I took the following steps in Power query:

  • What i already did was create an additional column with the first possible delivery date which is just the arrival date at the terminal +1.
  • Added a column with an index number.
  • Added a column with a batchgroup (grouping containers per 15)
  • Then i added a working calendar on which days we are open and can receive the 15 containers.

With these steps i tried to calculate the earliest possible delivery date with the following formula:

= let calendar = WorkingCalendar[WorkingDate], eligibleDates = List.Select(calendar, (d) => d >= [FirstPossibleDate]), deliveryDate = if List.Count(eligibleDates) > Number.IntegerDivide([Index], 15) then eligibleDates{Number.IntegerDivide([Index], 15)} else null in deliveryDate

On first sight this seems to work and it groups the containers to a maximum of 15 containers / day.

But when i take a closer look it does not fill the containers to a maximum of 15 / day and sometimes just skips days or start on a new day when the previous day only has 4 / 15 containers planned when there are others that could be booked on the same date.

I don’t seem to find the solution here... I think i might have to do someting with the first possible date changing and it automatically chooses a new delivery date.

(See example of when it changes to 17/06 when it should be 16/06. And only 1 container on 18/06)

I would really appreciate any help on this!!!

7 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/Ok_Dimension7436 Jul 09 '25

Hi John

Many thanks on your support on this, much appreciated!

Unfortunately the new function returns 'null' on all cases.Which is stranges as there are multiple possible dates...

My PowerQuery Knowlage is not good enough to understand what needs fixing atm...

2

u/johndering Jul 09 '25

Try editing a copy of WorkingCalendar[WorkingDate], deleting rows which are older than the current FirstPossibleDate values.

This is what I meant by edge cases :)

1

u/Ok_Dimension7436 Jul 09 '25

Aha!

We are getting somewhere now John 😁

The function seems tot work perfectlly doe exactly the first 100 cells but return 'null' after that.

Ik checked the calendar but there should ben dates available

1

u/Ok_Dimension7436 Jul 09 '25

This is the calendar

1

u/johndering Jul 09 '25

If you can possibly share a clean version of your Excel file with only the ATA column for the first table, and the Calendar table with only the WorkingDate column. Just these 2 tables with a single column each. Perhaps I can help you better.

1

u/Ok_Dimension7436 Jul 09 '25

Hi John

That would be great!

I am not sure how to share it on Reddit? There don't seems to be an option for that

1

u/johndering Jul 09 '25

Some folks used Google Drive to share Excel files, or something similar for file sharing.

1

u/Ok_Dimension7436 Jul 09 '25

Hi John

I will create a clean file and share it with you! Unfortunately I can't provide it today anymore so it Will ben tomorrow.

Many thanks!

2

u/johndering Jul 10 '25

Sorry OP, the better tables to share are:

  1. Table_1 -- With "First_Possible_Date" and "Item" (can be used as index)
  2. Table_2 -- With "Working_Date"

And I would suggest that you also create a post in r/excel, for a dynamic array solution or Power Pivot (DAX).

Along the lines:
Please kindly help populate a column (or set of columns, like Min_Item + Max_Item + Item_Count in Table_2) in either Table_1 or Table_2 for grouping of maximum 15 Table_1 Items per Working_Date >= First_Possible_Date.

2

u/johndering Jul 10 '25

Sorry, cannot wait, I posted a query already in r/excel. Hope some guru can suggest better alternative solution(s).

→ More replies