cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Anonymous
Not applicable

Returning SUM of MAX duration for bus trips to calculate total duration

Note - I want to do this in a measure, rather than a calculated column.

 

My data set comprises stop level data for bus routes, with timings, as well as a calculated column that calculates total elapsed duration. E.g. the following, where the result should be 840:

 

UniqueTripIDStopTimeRunningTimeDuration (calc column)
A17:00:00am0
A27:02:00am120
A37:04:00am240
A47:06:00am360
B18:00:00am0
B28:03:00am180
B38:05:00am300
B48:08:00am480

 

The total time for a trip is the MAX value for Calculated Duration for any given UniqueTripID (these are unique identifiers )

 

I've come up with a measure that works for individual level routes:

 

var maxtime = MAX(DATA_RADIOLA[RunningTripDuration])

var uniquetripid = MAX(DATA_RADIOLA[Unique TRIPID])

var routeresult =
CALCULATE(
MAX(
DATA_RADIOLA[RunningTripDuration]),
uniquetripid=DATA_RADIOLA[Unique TRIPID]
)

What I want to do is SUM the MAX for every unique TripID. The following does not work:
//CALCULATE(
// SUM(
// DATA_RADIOLA[RunningTripDuration]),
// DATA_RADIOLA[RunningTripDuration]=maxtime,
// DATA_RADIOLA[Unique TRIPID]=uniquetripid
//)
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

@Anonymous lbendlin_0-1639229750628.png

Max Cumul := 
var a = SUMMARIZE('DATA_RADIOLA','DATA_RADIOLA'[UniqueTripID],"maxlen",MAX('DATA_RADIOLA'[RunningTimeDuration (calc column)]))
return sumx(a,[maxlen])

 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

@Anonymous lbendlin_0-1639229750628.png

Max Cumul := 
var a = SUMMARIZE('DATA_RADIOLA','DATA_RADIOLA'[UniqueTripID],"maxlen",MAX('DATA_RADIOLA'[RunningTimeDuration (calc column)]))
return sumx(a,[maxlen])

 

Anonymous
Not applicable

Wonderful, works perfectly. Here is your result compared to one I created using a helper column (which slows down calculation time), and the difference is infinitesimal.
Thanks so much!!!

zhivana_0-1639339349968.png

 

you make a good point, especially on the impact of larger data sets on the performance. Instead of SUMMARIZE you can also use GROUPBY() or a variety of other approaches. In DAX Studio you can study the query plan and optimize your query as needed.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors