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
hmbedford
Frequent Visitor

Days Fleet Vehicle Available For Each Month

Hi All,

 

I am trying to calculate the days that a vehicle was available for each month that it was on fleet. Vehicles can span multiple months and cover partial months. I am pulling 12 months worth of data and here is a small example of the data.

 

VehicleStart_Fleet_DateEnd_Fleet_Date
Car 120/Nov/201903/Mar/2020
Car 229/Sep/201926/Feb/2020
Car 310/Aug/201910/Jan/2020

 

For each vehicle i need to be able to calculate the days that the vehicle was available for each month that the data set spans. For example

 

VehicleAug 19Sep 19Oct 19Nov 19Dec 19Jan 20Feb 20Mar 20
Car 1000103131293
Car 20231303131260
Car 321303130311000

 

Once i have this i can then align to the bookings and have a monthly utilisation for each vehicle/model.

 

I am struggling how to calculate each individual month for each row of data.

 

Appreciate any help or suggestions

 

Thanks

Hayden

1 ACCEPTED SOLUTION
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/

View solution in original post

12 REPLIES 12
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/

I work for a nonprofit school for children with autism and we have multiple vans for outings.
My boss has asked me to show data on whether or not we have to many vehicles and can we get rid of any.
I have the dates and number of times each vehicle was driven but I am not sure how to organize it. I did it by percentages and broke it out monthly for the last six months but that is not giving me what I need.

Here is one month of data but I'm not sure how to show the data on any vehicle can be gotten rid of. My vehicle data is van # in column 1 and dates along row 1 starting in column 2 :  4/10/2023       4/11/2023       4/12/2023       4/13/2023       4/14/2023       4/17/2023       4/18/2023       4/19/2023       4/20/2023       4/21/2023       4/24/2023       4/25/2023       4/26/2023       4/27/2023       4/28/2023


#1 (Acd)        17              6       2                       11      12      6                                       2       
#2 (Acd)        16      1       6       2       1       1       11      12      6               1               1       2       1
#5 (Acd)        16              6       2                       11      12      6                                       2       
#15 (Acd)                       1       1       8                       2       11      6                                       
#16 (Acd)                               1       8                               11      8                                       
#17 (Acd)                               1       8                               10      8                                       
#18 (LS)                1       1       2               1       1                               1               1               
#19 (EA)                                1       1               1                                       1                       
#23 (Res)       3       2       3       8       5                               1       2       4               4       6       4
#24 (Res)                                                                                                                       
#28 (Ls)                                                                                                                       
#29 (Res)       5       9       3       9       5       4       4       5       6       2       5       5       6       4       4

Thank you so much for your help in this.

Hello

I have a similar problem and the solution proposed would serve me but I do not have a table with each of the dates of each car, according to the period that has been active.

What I have is a table with all the cars, 1 in each row, and 2 columns with "high date" and "low date".

How do I get the days that each car has been active and each month of each year?

Thank you.

Hi,

Share some data and show the expected result.


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

Hello

I have a table similar to this

License plateMarchRegistration DateLow Date
0557LWDVW LCV02/02/2022 04:02:32
0706LNSVOLKSWAGEN26/05/2022 09:05:21
0825LWRVW LCV11/03/2022 10:03:48
0841LPKVOLKSWAGEN19/07/2022 03:07:34
1137LNJVW LCV31/03/2021 04:03:27
0006LBNVOLKSWAGEN07/10/2019 06:10:0904/09/2020 00:00
0007LBNVOLKSWAGEN10/10/2019 12:10:5927/08/2020 00:00
0009LBNVOLKSWAGEN07/10/2019 06:10:4931/08/2020 00:00
0010LBNVOLKSWAGEN10/10/2019 12:10:0313/01/2021 00:00
0014LBNVOLKSWAGEN08/10/2019 12:10:4404/07/2020 00:00
0056KMWVOLKSWAGEN23/10/2019 11:10:4913/12/2019 00:00
5579LJKVOLKSWAGEN25/08/2020 04:08:4908/10/2020 00:00
5585LNVSEAT14/03/2022 12:03:1921/06/2022 00:00
5587LNVSEAT22/03/2022 03:03:2513/05/2022 00:00

I replace the blank cells with the last day of the full month for which I have data, in this case 31/8/22.

I am interested in knowing about each car the days it has been active (difference between date of registration and date of cancellation), by year and month and to be able to compare it with the days it has been in use or rented. Usage or rental data comes from another table where the issued contracts are collected. In this way you would have the occupation or rate of use of each car, by day, week, month, year, etc.

The correct result of occupancy days by month and year should be something like this:

Year 2022
License plateJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptember
0557LWD027313031303131
0706LNS00006303131
5585LNV001830312100
5587LNV00103013000

I hope I have been able to explain myself.

Thanks a lot.

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/

Fantastic!!!

It has served me and a lot.

I have it solved.

Thank you so much!!

You are welcome.  If my reply helped, please mark it as Answer.


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

Hi @Ashish_Mathur 

 

This worked a treat, thenk you very much

 

Regards

Hayden

You are welcome.


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

Possibly Open Tickets, it is designed to deal with date intervals. 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/td-p/409364


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
camargos88
Community Champion
Community Champion

Hi @hmbedford ,

 

First use this code on Edit Query -> Advanced Editor:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sUjBU0lEyMtD3yy/TNzIwtATyDIz1fROLgDwjA6VYHYgqI5AqS/3g1AKYKiMzfbfUJFRVxkBxQwN9x9J0mCogzysxD6oqFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Vehicle = _t, Start_Fleet_Date = _t, End_Fleet_Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Vehicle", type text}, {"Start_Fleet_Date", type date}, {"End_Fleet_Date", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Dates", each List.Dates([Start_Fleet_Date], Duration.Days([End_Fleet_Date] - [Start_Fleet_Date])+1, #duration(1, 0, 0, 0))),
#"Expanded Dates" = Table.ExpandListColumn(#"Added Custom", "Dates"),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Dates",{"Start_Fleet_Date", "End_Fleet_Date"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Dates", type date}})
in
#"Changed Type1"

 

After that, create this measure:

Qtd_Month =
VAR _start = CALCULATE(MIN('Table'[Dates]); FILTER(ALL('Date');'Date'[Year_Month] = SELECTEDVALUE('Date'[Year_Month])))
VAR _end = CALCULATE(MAX('Table'[Dates]); FILTER(ALL('Date');'Date'[Year_Month] = SELECTEDVALUE('Date'[Year_Month])))
VAR _result = INT(_end - _start)
RETURN IF(_result = BLANK(); 0; _result + 1)
 
I hope it helps,
 
Ricardo
 


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

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.