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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Proration-factor - calculate days within period compared to total duration

So a little background;

I am working with data for vessels and their voyages. Each voyage will have a start date and an end date, and I want to calculate the number of days within the chosen period as a proportion of the voyage total days.


This is for prorating within a chosen period, typically financial results within a Quarter, specified with a Slicer. 

 

To make it most flexible, I'm considering using a factor which could be applied to any data to represent the prorated values within the period.

 

One example:
Voyage starts March 15th and ends June 20th.


Period covers month 4-6 (2nd quarter):

Days before chosen period = 16
Days within chosen period = 91
Days after chosen period = 20
Total days = 127

I would then want to return the factor 91/127 = 0,7165

I've tried several IF-functions, but cannot get it to work properly.

 

Below is some sample data. End result should be the factor. 
Period example.JPG

 

Any tips on how to solve this is highly appreciated. 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

If you don't have one already, you should make a Date table that has a Quarter column.  For this analysis, you don't need a relationship between the tables, but you probably will for other analyses.  Below is a DAX measure expression you could adapt for your need.  It assumes you are in a matrix visual with Voyage on rows and Quarter on columns.

 

Pct Within Period =
VAR mindate =
    MIN ( Date[Date] )
VAR maxdate =
    MAX ( Date[Date] )
VAR totalvoyage =
    SUMX ( Voyage, Voyage[End] - Voyage[Start] )
VAR voyagestart =
    MIN ( Voyage[Start] )
VAR voyageend =
    MIN ( Voyage[End] )
VAR calcstart =
    IF ( mindate < voyagestart, voyagestart, mindate )
VAR calcend =
    IF ( maxdate > voyageend, voyageend, maxdate )
VAR daysinperiod = calcend - calcstart
RETURN
    DIVIDE ( daysinperiod, totalvoyage )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

If you don't have one already, you should make a Date table that has a Quarter column.  For this analysis, you don't need a relationship between the tables, but you probably will for other analyses.  Below is a DAX measure expression you could adapt for your need.  It assumes you are in a matrix visual with Voyage on rows and Quarter on columns.

 

Pct Within Period =
VAR mindate =
    MIN ( Date[Date] )
VAR maxdate =
    MAX ( Date[Date] )
VAR totalvoyage =
    SUMX ( Voyage, Voyage[End] - Voyage[Start] )
VAR voyagestart =
    MIN ( Voyage[Start] )
VAR voyageend =
    MIN ( Voyage[End] )
VAR calcstart =
    IF ( mindate < voyagestart, voyagestart, mindate )
VAR calcend =
    IF ( maxdate > voyageend, voyageend, maxdate )
VAR daysinperiod = calcend - calcstart
RETURN
    DIVIDE ( daysinperiod, totalvoyage )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

I get this to work per voyage/row. 

However I cannot make it work on aggregated levels, meaning per vessel. 

 

Please consider below data and setup: 

Period example2.JPG

 

This is the relationship between the tables: 

Table relationships.JPG

 

I would then like to present a sum per vessel by vessel name. Key point here is the sum of the two voyages for Ship3. 

So something like this: 

 

End result.JPG

 

When I try this now, I get no results. 

Anonymous
Not applicable

Thanks! 

 

It brings me 95% of the way - added a few tweaks for filtering a bit, but otherwise I'm nearly there. 

 

I will work a bit more on this concept, but this is the closest I've ever been to a solution. 

 

Main issues going forward is to be able to maintain filters when I combine data from different tables in the same Table visual. 

I end up with alot of blank rows when adding columns from other tables, but expect that to be an issue with missing relations and filtering.  

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors