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
xonder
Helper I
Helper I

Calculating days between first and last order by product

Hi There,

 

I have a data set that includes vhcid(Vehicle ID) and data_date.

 

In the matrix below, I would like to calculate the number of days a vehicle has been online. Below, for example, vehivle 7985400 has been online since 5th October until the 23rd October, or 18 days.

 

I tried the follwoing DAX:

 

 

days_online = 1*(MAX(Downloads[data_date])-MIN(Downloads[data_date]))

 

 

 

As you see it returns an odd result of 60 days for all lines. This actually corresponds to the difference between the first and last dates in my entier data set. Not for a specific vhcid as I would like.

 

Capture.PNG

 

The FIRSTDATE and LASTDATE DAX functions did not yield much either.

 

I would like to return a table with [vhcid] and [days_online]

 

Thanks for your help!!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@xonder , try like

days_online = calculate(datediff(MIN(Downloads[data_date]),MAX(Downloads[data_date]),day), allexcpet(Downloads, Downloads[vchid]))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@xonder , try like

days_online = calculate(datediff(MIN(Downloads[data_date]),MAX(Downloads[data_date]),day), allexcpet(Downloads, Downloads[vchid]))

Thanks, amitchandak. Works!

 

The solution works provided I summerize as average.

 

Never thought such a simple idea would need such a complex formula.

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.