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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Blizzardstyx
Frequent Visitor

Utilization of Asset by Month

Hello All,

 

I have two tables (asset table with basic information) and an Activity table. My activity table has the asset ID and a pickup date and return date (see example below). I need to find out how many days of a month that my asset was utilized. The issue I'm having are that there are overlapping dates that I do not want to double count. 

 

Taking the table below let's say I'm looking for days utilized in January. Asset ID 5 should show a total of 3 days (not 4) because of the overlap issue. For Asset ID 10 I should have a total of 18 days. 

 

Activity IDAsset IDPickup DateReturn Date
738512/25/20191/3/2020
79951/3/20201/3/2020
5381012/15/20191/10/2020
809101/9/20201/18/2020

 

My end goal is to have a table like this:

Asset IDTotal days utilized
53
1018

 

Update: just found out how to add an example PBIX file:

https://drive.google.com/file/d/1lGBKt4dwywIGSP9tKue2RAoypo7alxzJ/view?usp=sharing

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi @Blizzardstyx ,

 

Ok so I have re thought this as come up with another way to solve this problem. New solution creates a new fact table called activities_filled with the following DAX (Table Tools -> New Table)

Activities_filled = SUMMARIZECOLUMNS(Activities[Tractor], 'Calendar'[Date],FILTER(CROSSJOIN('Calendar', Activities), 'Calendar'[Date] >='Activities'[Pickup Date].[Date] && 'Calendar'[Date] <= 'Activities'[Return Date]))

 

the formula performs the following:

- cross join calendar and activities table

- Filter where date >= pick up date && date <= return date

- return the distinct tractors and dates (removes the scenario where the pickup dates are the same)

 

 I can then join this to calendar and tractor to get utilization by tractor and date

 

I have saved to the same location



I hope this helps,
Richard

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

Proud to be a Super User!


View solution in original post

13 REPLIES 13
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur ,

 

Can you use your solution with the data set I provided?

 

It looks like your date range is a custom list of dates that happens to work with the two examples I provided. I think this solution might have trouble with 100+ activities. 

Hi,

I do not know which dataset you have provided.  Try my solution on your dataset and let me know what problems you face.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I don't even know how to implement your solution to my problem.. there's a link in the question to a pbix file. Are you having trouble accessing it?

richbenmintz
Solution Sage
Solution Sage

Hi @Blizzardstyx ,

 

I created a sample prior to you uploading your file, with what i think is a workable solution:

step 1: create a date table 

 

Calendar = calendar("2019-01-01", "2020-12-31")

 

Join Calendar to the pickupdate column in the activity table

create the measure

 

Days Utilized = 
var minDate = MIN(Activities[PickupDate])
var maxDate = MAX(Activities[ReturnDate])
var minPeriodSelectedDate = MIN('Calendar'[Date])
return 
if(minDate < minPeriodSelectedDate, DATEDIFF(minPeriodSelectedDate , maxDate,DAY)+1,
DATEDIFF(minDate, maxDate, DAY)+1)

 

 file for you to review

sample pbix download 

 

hope this helps

Richard

 



I hope this helps,
Richard

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

Proud to be a Super User!


amitchandak
Super User
Super User

Refer to this solution : https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

In the current year calc, you can ignore blank handling and you have date diff between start and max and max and end added up

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

I have an example PBIX file, how do I add? 😕

@Blizzardstyx 

you can save to onedrive or google drive and share a link to the file



I hope this helps,
Richard

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

Proud to be a Super User!


Hi @Blizzardstyx 

 

I have updated your file with a measure they I believe provides you with what you need

 

Days Utilized = 
var minDate = MIN(Activities[Pickup Date])
var allmaxDate = CALCULATE(MAX(Activities[Return Date]), ALLEXCEPT(Activities,'Activities'[Tractor]))
var maxDate = max('Activities'[Return Date])
var minPeriodSelectedDate = MIN('Calendar'[Date])
var maxPeriodSelectedDate = MAX('Calendar'[Date])
return 
SWITCH(TRUE(), ISBLANK(minDate), BLANK(),
minDate < minPeriodSelectedDate && allmaxDate > maxPeriodSelectedDate, DATEDIFF([minPeriodSelectedDate], maxPeriodSelectedDate,DAY)+1,
minDate < minPeriodSelectedDate, DATEDIFF(minPeriodSelectedDate, maxDate,DAY)+1,
maxDate > maxPeriodSelectedDate, DATEDIFF([minDate], maxPeriodSelectedDate,DAY)+1,
DATEDIFF(minDate, maxDate, DAY)+1)

 

basically find following variables:

minDate: the minimum pickup date of the assest that was dropped off in the selected period

allmaxDate: the maximun drop off date of an asset dropped of in the selected period

maxDate: maximum return date of the asset that was returned in the selected period

minPeriodSelectedDate: the min date of the selected period

maxPeriodSelectedDate: the max date of the selected period

 

then conditionally determine the date difference based on whether

- the item was borrowed in a prior per, returned this period, borrowed again and will be returned in the future

- the item was borrowed in a prior period and returned this period

- the item was borrowed this period and will be returned in a future period

- the item was borrowed and returned in this period

 

One case that i have not captured are assests borrowed in prior periods and not returned in the current period, however i will leave that challenge to you 😁

 

link to your sample file with my mods 

 



I hope this helps,
Richard

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

Proud to be a Super User!


@Rich 

Thanks for the thorough reply!

 

I think something is a little off though.

 

I filtered for a Asset ID 1676 and it doesn't look right. It only has two activities yet it's showing 30 days of utilization?

1/2/2020 -> 1/9/2020

1/30/2020 -> 1/31/2020

 

 

Hi @Blizzardstyx ,

 

Ok so I have re thought this as come up with another way to solve this problem. New solution creates a new fact table called activities_filled with the following DAX (Table Tools -> New Table)

Activities_filled = SUMMARIZECOLUMNS(Activities[Tractor], 'Calendar'[Date],FILTER(CROSSJOIN('Calendar', Activities), 'Calendar'[Date] >='Activities'[Pickup Date].[Date] && 'Calendar'[Date] <= 'Activities'[Return Date]))

 

the formula performs the following:

- cross join calendar and activities table

- Filter where date >= pick up date && date <= return date

- return the distinct tractors and dates (removes the scenario where the pickup dates are the same)

 

 I can then join this to calendar and tractor to get utilization by tractor and date

 

I have saved to the same location



I hope this helps,
Richard

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

Proud to be a Super User!


Hi @Blizzardstyx ,

 

I will have a look tomorrow, My thought is that the item has a date returned in a future month, will review the though and try to fix it



I hope this helps,
Richard

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

Proud to be a Super User!


@Blizzardstyx , 

I see the issue, need to deal with non contigous date ranges within a period, ie break between check in and next check out, in a meeting all day, will review and fix as soon as i can



I hope this helps,
Richard

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

Proud to be a Super User!


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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