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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
tspearman
Regular Visitor

Count volume if one date is before and one date is after specified date

I am completely stumped by this - I hope this is within PBI capability as would be fantastically useful.

 

I have a ship, that loads cargo at A, B and C. It then discharges at B, C, and D. I want to know what volume of cargo I have on the ship at A, B, C and D.

 

The data I have is:

 

LoadLdateDischargeDdateVolume
A1/01/2019B5/01/20193
B5/01/2019D28/01/20196
C14/01/2019D28/01/20194
A1/01/2019C14/01/201921
C14/01/2019D28/01/20193
A1/01/2019B5/01/20196
B5/01/2019C14/01/201965
A1/01/2019D28/01/201923

 

 

I am looking to create a measure(s) that will yeild the below:

 

PortVolume
A53
B115
C36
D0

 

 

Any help much appreciated

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@tspearman 

Here is my suggestion on how to set this up (I have attached a PBIX).

 

  1. Transform your Load/Discharge data into this form, by splitting Load & Discharge into two tables then appending them into a single table. I called this table Cargoimage.png

    Note that Volume Signed is positive for Load and negative for Discharge.

  2. Create a Date table and a Location table. Location just contains distinct Locations i.e. A,B,C,D.
  3. Data model looks like this:image.png

     

  4. Create these measures:
    Volume Cumulative = 
    VAR GlobalMaxCargoDate = CALCULATE ( MAX ( Cargo[Date] ), ALL () )
    RETURN
        IF (
            MIN ( 'Date'[Date] ) <= GlobalMaxCargoDate,
            CALCULATE(
                SUM ( Cargo[Volume Signed] ),
                DATESBETWEEN('Date'[Date], BLANK(), MAX('Date'[Date]))
            )
        )
    
    Volume Cumulative up to Filtered Location = 
    CALCULATE(
        [Volume Cumulative],
        SUMMARIZE ( Cargo, 'Date'[Date] ),
        ALL ( Location ) // If your model is more complex, you may need to be more specific about what is in this ALL
    )
    The 2nd measure grabs the Dates that are currently visible in the Cargo table, turns them into a Date[Date] filter, then calculates [Volume Cumulative] as at those dates (effectively the maximum of those dates), with the Location filter cleared with ALL.
  5. Now you can visualize [Volume Cumulative up to Filtered Location] filtered by Location[Location]image.png

     

Please post back if needed.

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

@tspearman 

Here is my suggestion on how to set this up (I have attached a PBIX).

 

  1. Transform your Load/Discharge data into this form, by splitting Load & Discharge into two tables then appending them into a single table. I called this table Cargoimage.png

    Note that Volume Signed is positive for Load and negative for Discharge.

  2. Create a Date table and a Location table. Location just contains distinct Locations i.e. A,B,C,D.
  3. Data model looks like this:image.png

     

  4. Create these measures:
    Volume Cumulative = 
    VAR GlobalMaxCargoDate = CALCULATE ( MAX ( Cargo[Date] ), ALL () )
    RETURN
        IF (
            MIN ( 'Date'[Date] ) <= GlobalMaxCargoDate,
            CALCULATE(
                SUM ( Cargo[Volume Signed] ),
                DATESBETWEEN('Date'[Date], BLANK(), MAX('Date'[Date]))
            )
        )
    
    Volume Cumulative up to Filtered Location = 
    CALCULATE(
        [Volume Cumulative],
        SUMMARIZE ( Cargo, 'Date'[Date] ),
        ALL ( Location ) // If your model is more complex, you may need to be more specific about what is in this ALL
    )
    The 2nd measure grabs the Dates that are currently visible in the Cargo table, turns them into a Date[Date] filter, then calculates [Volume Cumulative] as at those dates (effectively the maximum of those dates), with the Location filter cleared with ALL.
  5. Now you can visualize [Volume Cumulative up to Filtered Location] filtered by Location[Location]image.png

     

Please post back if needed.

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors