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
Anonymous
Not applicable

FILTER and SUM

Hi, 

 

I am trying to create a measure/column with below example on PowerBI.  I need the selected filter from 'activity' and its 'duration' summed up into the result which also needs to relate and be connected to the 'Name' and 'Date' column as shown in my example. 

 

Aziza_0-1614704058882.png

 

Please can you advise what would be the best option? I have tried different DAX formulas but getting error or wrong result everytime. 

 

Thank you very much. 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download PBIX file with the data and code below

 

The Data Model in Power BI doesn't have a duration data type so the times you have in your table for the Duration column will be stored as decimal numbers.

However you can still format these numbers as 'time/duration' as you have shown by using this measure

Total Time = 

VAR Sum_Elapsed_Time = CALCULATE(SUM('Table'[Duration]), FILTER(ALL('Table'), 'Table'[Date] = SELECTEDVALUE('Table'[Date]) && 'Table'[Name] = SELECTEDVALUE('Table'[Name])))

VAR _hrs = Sum_Elapsed_Time * 24
VAR hrs = INT(_hrs)
VAR _mins = (_hrs - hrs) * 60
VAR mins = INT((_hrs - hrs) * 60)
VAR secs = ROUND((_mins - mins)*60,0)

RETURN

FORMAT(hrs,"00") & ":" & FORMAT(mins,"00") & ":" & secs

 

which gives this

dur1.png

 

I've left the Duration and Result columns just so you can see how the durations are stored.  These can be removed from the visual. 

If you want you could also create another column to display the Duration values formatted in the same way that the Total Time column is.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

3 REPLIES 3
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download PBIX file with the data and code below

 

The Data Model in Power BI doesn't have a duration data type so the times you have in your table for the Duration column will be stored as decimal numbers.

However you can still format these numbers as 'time/duration' as you have shown by using this measure

Total Time = 

VAR Sum_Elapsed_Time = CALCULATE(SUM('Table'[Duration]), FILTER(ALL('Table'), 'Table'[Date] = SELECTEDVALUE('Table'[Date]) && 'Table'[Name] = SELECTEDVALUE('Table'[Name])))

VAR _hrs = Sum_Elapsed_Time * 24
VAR hrs = INT(_hrs)
VAR _mins = (_hrs - hrs) * 60
VAR mins = INT((_hrs - hrs) * 60)
VAR secs = ROUND((_mins - mins)*60,0)

RETURN

FORMAT(hrs,"00") & ":" & FORMAT(mins,"00") & ":" & secs

 

which gives this

dur1.png

 

I've left the Duration and Result columns just so you can see how the durations are stored.  These can be removed from the visual. 

If you want you could also create another column to display the Duration values formatted in the same way that the Total Time column is.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi, apologies for the late reply and thank you so much for your help. 

 

My only question is how can I filter 'Activity' column by "Break" and "Lunch"? I will need to filter more options from Acitivity column too

 

Thank you very much 

Anonymous
Not applicable

I did manage to get it now so no worries. Thank you for your help 🙂 

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.

Top Solution Authors