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

Hi Team, could you pls help me to create this calculated table by using dax

Column Names: Date, Max ETA Date, Market, Container Number, Capacity

Metrics to Calculate:

  1. Number of Containers Delivered (Daily):
    Every day, only a limited number of containers can be delivered based on the available capacity.

    • Example: If the capacity is 5, then only 5 containers can be delivered that day.
  2. Number of Containers Pending Delivery (Daily):
    This is the number of containers that are still waiting to be delivered.

    • Formula:
      Pending = Total Containers - Delivered
      This includes containers from previous days that weren’t delivered due to capacity limits.
  3. Total Containers (Daily):
    This is the sum of:

    • Containers that were pending from the previous day, and
    • New containers added on the current day.
    • Formula:
      Total = Previous Day's Pending + Today's New Containers

      sample out put
      MarketDateMax eta date No of containers arrivedCapacityNo of containers deliverdpendingTotal
      India 11-11-202411-11-2024235518 
      India 12-11-202412-11-202424553742
      India 13-11-2024  553237
      India 14-11-2024  552732
      India 15-11-2024  552227
      India 16-11-2024  551722
      India 17-11-2024  551217
      India 18-11-2024  55712
      India 19-11-2024  5527
      India 20-11-202420-11-202435505
      India 21-11-202421-11-2024 55-50
      India 22-11-202422-11-2024555-50
      India 23-11-202423-11-2024 55-10-5
      India 24-11-202424-11-2024 55-15-10

 

6 REPLIES 6
v-hashadapu
Community Support
Community Support

Hi @tkavitha911 , Thank you for reaching out to the Microsoft Community Forum.

 

Based on your description, I took some sample data and worked out the solution.

Please refer attached .pbix file for reference and share your thoughts.

 

If this helped solve the issue, please consider marking it “Accept as Solution” so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.

techies
Solution Sage
Solution Sage

Hi @tkavitha911 have split the logic into parts by creating intermediate calculated tables, please try this

 

first create a base weekday table

 

BaseWeekdayTable =
FILTER (
    ADDCOLUMNS (
        SUMMARIZE (
            Containers,
            Containers[Market],
            Containers[Date],
            Containers[Max ETA Date]
        ),
        "NoOfContainersArrived",
            CALCULATE (
                COUNTROWS ( Containers ),
                ALLEXCEPT ( Containers, Containers[Market], Containers[Date] )
            ),
        "Capacity",
            CALCULATE (
                MAX ( Containers[Capacity] ),
                ALLEXCEPT ( Containers, Containers[Market], Containers[Date] )
            )
    ),
    WEEKDAY ( [Date], 2 ) <= 5  // Monday to Friday
)
 
 
Then add row numbers to sort --- calculate table
 
WeekdayWithRowNumber =
ADDCOLUMNS (
    BaseWeekdayTable,
    "RowNumber",
        RANKX (
            FILTER (
                BaseWeekdayTable,
                [Market] = EARLIER ( [Market] )
            ),
            [Date],
            ,
            ASC
        )
)
 
this is the final table
 
DeliverySummaryWeekdays final =
ADDCOLUMNS (
    WeekdayWithRowNumber,
   
    "Total",
        VAR CurrentMarket = [Market]
        VAR CurrentRow = [RowNumber]
        VAR PrevRows =
            FILTER (
                WeekdayWithRowNumber,
                [Market] = CurrentMarket &&
                [RowNumber] < CurrentRow
            )
        VAR PrevPending =
            SUMX (
                PrevRows,
                VAR Arr = [NoOfContainersArrived]
                VAR Cap = [Capacity]
                VAR Delivered = MIN ( Arr, Cap )
                RETURN Arr - Delivered
            )
        RETURN [NoOfContainersArrived] + PrevPending,

    "No of Containers Delivered",
        VAR CurrentMarket = [Market]
        VAR CurrentRow = [RowNumber]
        VAR PrevRows =
            FILTER (
                WeekdayWithRowNumber,
                [Market] = CurrentMarket &&
                [RowNumber] < CurrentRow
            )
        VAR PrevPending =
            SUMX (
                PrevRows,
                VAR Arr = [NoOfContainersArrived]
                VAR Cap = [Capacity]
                VAR Delivered = MIN ( Arr, Cap )
                RETURN Arr - Delivered
            )
        VAR TotalToday = [NoOfContainersArrived] + PrevPending
        RETURN MIN ( TotalToday, [Capacity] ),

    "Pending",
        VAR CurrentMarket = [Market]
        VAR CurrentRow = [RowNumber]
        VAR PrevRows =
            FILTER (
                WeekdayWithRowNumber,
                [Market] = CurrentMarket &&
                [RowNumber] < CurrentRow
            )
        VAR PrevPending =
            SUMX (
                PrevRows,
                VAR Arr = [NoOfContainersArrived]
                VAR Cap = [Capacity]
                VAR Delivered = MIN ( Arr, Cap )
                RETURN Arr - Delivered
            )
        VAR TotalToday = [NoOfContainersArrived] + PrevPending
        VAR DeliveredToday = MIN ( TotalToday, [Capacity] )
        RETURN TotalToday - DeliveredToday
)
 
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

first table working fine but second table bit confusion about this WeekdayWithRowNumber

Hi @tkavitha911 this will just show row number, for looping purposes, like this

 

techies_0-1750140966265.png

 

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
bhanu_gautam
Super User
Super User

@tkavitha911 , Create measures using

// Calculate the total containers for each day
Total Containers =
VAR PreviousDayPending =
CALCULATE(
SUM('Table'[Pending]),
FILTER('Table', 'Table'[Date] = EARLIER('Table'[Date]) - 1)
)
RETURN
IF(
ISBLANK(PreviousDayPending),
'Table'[No of containers arrived],
PreviousDayPending + 'Table'[No of containers arrived]
)

// Calculate the number of containers delivered each day
No of Containers Delivered =
MIN('Table'[Capacity], 'Table'[Total Containers])

// Calculate the number of containers pending delivery each day
Pending =
'Table'[Total Containers] - 'Table'[No of Containers Delivered]

 

Create a calculated column for each metric:

Total Containers =
VAR PreviousDayPending =
CALCULATE(
SUM('Table'[Pending]),
FILTER('Table', 'Table'[Date] = EARLIER('Table'[Date]) - 1)
)
RETURN
IF(
ISBLANK(PreviousDayPending),
'Table'[No of containers arrived],
PreviousDayPending + 'Table'[No of containers arrived]
)

 

No of Containers Delivered =
MIN('Table'[Capacity], 'Table'[Total Containers])

 

Pending =
'Table'[Total Containers] - 'Table'[No of Containers Delivered]




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

Proud to be a Super User!




LinkedIn






Need calculated table for only week days 

 

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.