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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kbuckvol
Advocate I
Advocate I

Get duration in days of event per year

I have a  collection of projects that begin and end at different dates, some within the same year and some span several years.  I need a way quickly create a matrix that shows how many days within each year the project occured.  I'm sure this is a filter of some kind, but I'm struggling to put it together.  The ultimate goal is to create another matrix that shows the percentage of days within each year that the project fell in.  In my sample table, I have the first four left columns, but I'm trying to figure out the next five.

 

ProjectBeginEndduration20222023202420252026
A1/10/20224/30/2022110110    
B11/16/20235/29/2024195 45150  
C5/16/20241/15/2025244  22915 
D9/19/20241/9/2026477  1033659
E9/19/202412/22/2025459  103356 
F12/19/202412/29/2026740  12365363
G4/21/20259/30/2025162   162 
H5/1/202512/30/2025243   243 

 

ProjectBeginEndduration20222023202420252026
A1/10/20224/30/2022110100%    
B11/16/20235/29/2024195 23%77%  
C5/16/20241/15/2025244  94%6% 
D9/19/20241/9/2026477  22%77%2%
E9/19/202412/22/2025459  22%78% 
F12/19/202412/29/2026740  2%49%49%
G4/21/20259/30/2025162   100% 
H5/1/202512/30/2025243   100% 

 

1 ACCEPTED SOLUTION
bolfri
Super User
Super User

Sample data that I have used:

bolfri_0-1671585218597.png

Step 1: Create dim_calendar that contains all the dates from Jan 1st from first year in your data till Dec 31th in last year in your data

dim_calendar =
CALENDAR(
    DATE(YEAR(FIRSTDATE('Sample'[Status Start Date]));1;1);
    DATE(YEAR(LASTDATE('Sample'[Status End Date]));12;31)
)
Step 2: Add a year column in this table
Year = YEAR([Date])
 
Step 3: Create count days measure
We know from context that each row is a one day.
Count days = COUNTROWS(dim_calendar)

Step 4. Viz how many days we have got in each year
bolfri_1-1671585436082.png

Step 5. Calculate program duration measure
min_date > find min_date of Start date for program defined in Sample table

max_date > find max_date of Max date for program defined in Sample table

Note that this can be used to provide agregation for programs, which starts and ends in different dates.

Program duration =
var min_date = MINX('Sample';FIRSTDATE('Sample'[Status Start Date]))
var max_date = MAXX('Sample';LASTDATE('Sample'[Status End Date]))
return
    CALCULATE(
        [Count days];
        DATESBETWEEN(dim_calendar[Date];min_date;max_date))
 
Bonus: Define Percentage days for each year
Percentage days = DIVIDE([Program duration];[Count days])
 
Result:
bolfri_2-1671585646068.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
bolfri
Super User
Super User

Sample data that I have used:

bolfri_0-1671585218597.png

Step 1: Create dim_calendar that contains all the dates from Jan 1st from first year in your data till Dec 31th in last year in your data

dim_calendar =
CALENDAR(
    DATE(YEAR(FIRSTDATE('Sample'[Status Start Date]));1;1);
    DATE(YEAR(LASTDATE('Sample'[Status End Date]));12;31)
)
Step 2: Add a year column in this table
Year = YEAR([Date])
 
Step 3: Create count days measure
We know from context that each row is a one day.
Count days = COUNTROWS(dim_calendar)

Step 4. Viz how many days we have got in each year
bolfri_1-1671585436082.png

Step 5. Calculate program duration measure
min_date > find min_date of Start date for program defined in Sample table

max_date > find max_date of Max date for program defined in Sample table

Note that this can be used to provide agregation for programs, which starts and ends in different dates.

Program duration =
var min_date = MINX('Sample';FIRSTDATE('Sample'[Status Start Date]))
var max_date = MAXX('Sample';LASTDATE('Sample'[Status End Date]))
return
    CALCULATE(
        [Count days];
        DATESBETWEEN(dim_calendar[Date];min_date;max_date))
 
Bonus: Define Percentage days for each year
Percentage days = DIVIDE([Program duration];[Count days])
 
Result:
bolfri_2-1671585646068.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.