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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AtchayaP
Helper V
Helper V

undefined

16443349021164829383059542567248.jpg

How to find time spent to solve assignment 1 and assignment 2.

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @AtchayaP 

 

Ensure [Time created] and [Time closed] columns are both of Time data type, then you can create a new column with below DAX. This returns spent time in seconds for every row. 

Time in Second = DATEDIFF('Table'[Time created],'Table'[Time closed],SECOND)

vjingzhang_0-1644561855581.png

 

Then create a measure to calculate the total of time spent. I format it to show result like "xx h xx m xx s".

Time Spent = 
VAR _totalSeconds = SUM('Table'[Time in Second])
VAR _hours = INT(_totalSeconds/3600)
VAR _minutes = INT(MOD(_totalSeconds,3600)/60)
VAR _seconds = MOD(MOD(_totalSeconds,3600),60)
RETURN
_hours&"h"&_minutes&"m"&_seconds&"s"

vjingzhang_1-1644562983767.png

 

If you drag [Time in Second] column into a card visual directly and select SUM aggregation type for it, it will show the total time spent in seconds. It equals to above result. 

vjingzhang_2-1644563198875.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @AtchayaP 

 

Ensure [Time created] and [Time closed] columns are both of Time data type, then you can create a new column with below DAX. This returns spent time in seconds for every row. 

Time in Second = DATEDIFF('Table'[Time created],'Table'[Time closed],SECOND)

vjingzhang_0-1644561855581.png

 

Then create a measure to calculate the total of time spent. I format it to show result like "xx h xx m xx s".

Time Spent = 
VAR _totalSeconds = SUM('Table'[Time in Second])
VAR _hours = INT(_totalSeconds/3600)
VAR _minutes = INT(MOD(_totalSeconds,3600)/60)
VAR _seconds = MOD(MOD(_totalSeconds,3600),60)
RETURN
_hours&"h"&_minutes&"m"&_seconds&"s"

vjingzhang_1-1644562983767.png

 

If you drag [Time in Second] column into a card visual directly and select SUM aggregation type for it, it will show the total time spent in seconds. It equals to above result. 

vjingzhang_2-1644563198875.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Whitewater100
Solution Sage
Solution Sage

Hello:

You can solve this in Power Query:

Add new column > custom column > enter this formula: Duration.TotalSeconds([End Time]-[Start Time])
This will return result in total difference in seconds.
For difference in minutes this is the formula: Duration.TotalMinutes([End Time]-[Start Time])

Convert data type to decimal as the answer first ocomes out as text.

I got 10457854:14:00  in card visual.should I format this?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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