How to Sum Hours, Minutes, and Seconds with DAX in Power BI [h:nn:ss]

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • In this lesson, I'll show you how to sum hours, minutes, and seconds with DAX in Power BI.
    Please navigate through the content below:
    0:38 Agenda
    0:56 DAX functions to be successful in this tutorial
    1:50 Case
    Content Link: drive.google.c...
    ___________
    Highly recommended Power BI books (Affiliate links):
    ***The Definitive Guide to DAX: Business Intelligence for Microsoft Power BI, SQL Server Analysis Services, and Excel Second Edition: amzn.to/3ldPLpk
    ***DAX Patterns (Second Edition): amzn.to/3fBKdnD
    ***Analyzing Data with Power BI and Power Pivot for Excel: amzn.to/3fDPLOd
    ***Beginning DAX with Power BI: amzn.to/3fDEe1k
    ***Storytelling with Data: A Data Visualization Guide for Business Professionals: amzn.to/3mfPcwE
    ***Storytelling with Data: Let's Practice!: amzn.to/36c6Cot
    ***Information Dashboard Design: amzn.to/2V61o7h
    ___________Relevant PBI Topics
    MEASURES vs CALCULATED COLUMNS in DAX: • MEASURES vs CALCULATED...
    How to Use the ALL DAX Function in Power BI: • How to Use the ALL DAX...
    How to Use the Filter DAX Function in Power BI [The Basics]: • How to Use the Filter ...
    How to Calculate PERCENTAGES in Power BI: • How to Calculate PERCE...
    How to COMBINE Tables in Power BI: • How to COMBINE Tables ...
    ____________
    [DISCLAIMER]: Some links included in this description might be affiliate links. If you purchase a product with those links, I might receive a small commission. However, there is no additional charge to you! I appreciate your support and this will help me provide you with free content on a weekly basis.
    If you like the content, feel free to buy me a cup of coffee 😀👇www.paypal.me/...
    If you don't want to miss anything, subscribe to our newsletter: vizxlization.c...
    ___________Please follow us on:
    Web: www.vizxlizati...
    LinkedIn: / vizxlization
    Twitter: / vizxlization
    Facebook: / vizxlization
    Instagram: / nestoradrianzen
    Leave your comments and questions below!
    Don't forget to subscribe!
    Thanks so much!
    #DAX #PowerBIDAX #vizxlization #hhmmss

КОМЕНТАРІ • 107

  • @sophiar5280
    @sophiar5280 3 роки тому +1

    Thanks for presenting this so clearly. Nice job!

    • @NestorAdrianzen
      @NestorAdrianzen  3 роки тому

      Sophia R, thanks for stopping by. Keep up the great work. Cheers

  • @5t1300
    @5t1300 22 дні тому

    Time Calculation is never simple. You did a great job breaking it down so it is easy to understand. Thank you!

  • @joelngige5776
    @joelngige5776 2 роки тому

    One of the best DAX video i have seen on how to handle time calculations in DAX. Thanks

  • @davidhart4032
    @davidhart4032 2 роки тому

    I used this for both sum and average in one table. Seriously the best video I could ever find!!

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Glad you found the content helpful, David! Keep it up!

  • @ricardocontreras
    @ricardocontreras 11 місяців тому

    Nestor. Can we use the new measure in a bar or column chart?. Thx

    • @NestorAdrianzen
      @NestorAdrianzen  11 місяців тому +1

      Ricardo, Thanks for stopping by. The best way to visualize this measure is in a table/matrix and card visual. The reason for that is that the data type of the measure is TEXT. I hope that helps. Cheers!

  • @adominionla2009
    @adominionla2009 2 роки тому +2

    This was SOOOOOOOOOOOOOOOOOOOOOO HELPFUL! Thank you.

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Glad it was helpful and thanks for your support, Ann!

  • @MrPhanisDav
    @MrPhanisDav 3 роки тому +3

    Do u have the example of ,I don't want to show 2d 10h 05m 20 s, but I want 58:05:20 I want that format,it is ez to make the right adjustment by your code? Any help it would appreciate,thanks in advanced

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Phanis,
      Thanks for stopping by. DAX is weird! I'm going to work on a tutorial to solve this question.
      In the meantime, having as a reference the code that I used in the tutorial, just remove the third and fourth variables and add the following piece of code instead: VAR HoursTotal = DaysTotal*24. Don't touch the remaining variables!
      Finally in the RETURN piece, just use the following: FORMAT(HoursInt,"00")&"h, "&FORMAT(MinutesInt,"00")&"m, "&FORMAT(SecondsTotal,"00")&"s "
      The result should be 89h, 20m, 53s.
      Cheers!

  • @deeperblue77
    @deeperblue77 Рік тому

    Really helpful and exactly what I needed. Thanks, Nestor!

  • @pratafwd
    @pratafwd Рік тому +1

    How can I use this on a bar chart to see evolution of time spending? Because the result is a text so it doesn’t work on a bar chart (unless I put it In decimal format but I want to see the d/h/m/s)

  • @jplouw8348
    @jplouw8348 2 роки тому

    Hi Nestor, great video with clear instructions. Just a quick one, how would you do an average of the time with your method. Thanks

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому +1

      JL, Thanks for your support. For averages, you just need to use the AVERAGEX function instead of SUMX. See below for details.
      VAR Total_Hours =
      AVERAGEX(
      Manufacturing,
      HOUR(Manufacturing[Time Spent]) + MINUTE(Manufacturing[Time Spent])/60 + SECOND(Manufacturing[Time Spent])/3600
      )

    • @jplouw8348
      @jplouw8348 2 роки тому

      @@NestorAdrianzen Thank you will check it out

  • @edwardcunningham3298
    @edwardcunningham3298 Рік тому

    This video was super helpful, but I’m just wondering if you could tell me what format the time needs to be in?
    My time is currently in seconds, but I can easily convert to decimal hours, or decimal minutes.
    Thanks!

    • @NestorAdrianzen
      @NestorAdrianzen  Рік тому

      Edward, Thanks for checking the content out. The data is in a TIME format: hours, minutes and seconds (h:nn:ss)

  • @PavelHodek
    @PavelHodek 9 місяців тому

    Thank you for nice solution. Is there a way to sort properly if values are eg. "3d, 10h, 20m, 30s"; "22d, 10h, 20m, 30s"? 3 is lower than 22, but values are strings and alphabetically there is bad sorting order.

  • @IvanCortinas_ES
    @IvanCortinas_ES 2 роки тому

    Another Superb video Nestor. Thank you for this detailed explanation!!!

  • @hazrahadee6257
    @hazrahadee6257 2 роки тому

    Hello, Nestor, Thank you for your doing this video! The explanation is clear and precise. I have a start time and end time for Events. How do I extra the duration for each event and then total it?

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому +2

      Hazra Hadee, Thanks for stopping by. Have you tried the DATEDIFF function? To find the total amount, you will need to create a measure as follow. You can also change the interval to days, hours, minutes, etc.
      Measure :=
      SUMX (
      Table,
      DATEDIFF(Table[Date1], Table[Date2], DAY)
      )

  • @datayoda74
    @datayoda74 2 роки тому

    Good explanation and exactly what I am looking for.

  • @mohamedyoussef8367
    @mohamedyoussef8367 Місяць тому

    Our dear professor, can you send the equation as the video is not clear to me? Thank you❤

  • @pm4bellingerj
    @pm4bellingerj 2 роки тому +1

    Nestor, Thanks for such a great video! Extremely easy to follow! Subscribed!
    Is there the option to remove the days and sum the hours?
    I'd like to show the user the following format (45h, 35m, 00s)
    Thanks in advance and keep up the good work!

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      James, I appreciate your feedback. There should definitely be way to do so. I'll add your suggestion to my list. Cheers!

    • @noelsamulde464
      @noelsamulde464 2 роки тому

      @@NestorAdrianzen I am your new sub and I tried to follow your vid but got an error. By any chance , can you help?

    • @manoulomanoulo7
      @manoulomanoulo7 2 роки тому

      Hey James! Did you find a solution to your problem? I had a job interview and they sent me a task to complete.
      I have to sum hours and minutes in Power BI using the format you suggested. Thank you in advcance.

    • @pm4bellingerj
      @pm4bellingerj 2 роки тому +1

      @@manoulomanoulo7 hey bud.
      Yes I did! See below the code I’m using
      Total Trg Hours New =
      VAR TotalSeconds=SUMX('Training & Stds',HOUR('Training & Stds'[Total Trg Hours Total])*3600+MINUTE('Training & Stds'[Total Trg Hours Total])*60+SECOND('Training & Stds'[Total Trg Hours Total]))
      VAR Days =TRUNC(TotalSeconds/3600/24)
      VAR Hours = TRUNC((TotalSeconds-Days*3600*24)/3600)
      VAR Mins =TRUNC(MOD(TotalSeconds,3600)/60)
      VAR Secs = MOD(TotalSeconds,60)
      return IF((Hours + (Days*24))

    • @manoulomanoulo7
      @manoulomanoulo7 2 роки тому

      @@pm4bellingerj Thank you so much bro! I appreciate your help.

  • @bentatlim
    @bentatlim 8 місяців тому

    Thank you !!! Really well explained. I have a question about the time functions in power query. I loaded my table into power query and get an error message for durations greater than 24 hours (for example: 45:30:30). How can I solve this? I want to keep this format (Hours:Minutes:Seconds) But power query has a problem with it. when i sum my duration, I want it to be able to summarize it. For example a result like 145:29:30. ( 145 hours and 29 minutes and 30 seconds). I hope you can help me. Thanks in advance. Regards from Germany

    • @carlanmartins
      @carlanmartins 4 місяці тому

      i have the exact same problem, did you manage to solve it? tks (im still searching for a solution)

    • @NestorAdrianzen
      @NestorAdrianzen  3 місяці тому

      I haven't tried solving this in Power Query. Let me know how it goes!
      If you want to keep hours:minutes:seconds, please review this tutorial. --> still using DAX for this analysis though. ua-cam.com/video/Xt0FCt-h66M/v-deo.htmlsi=88m-yJjQgM90Ztag

    • @NestorAdrianzen
      @NestorAdrianzen  3 місяці тому

      Check out this tutorial to get the result in hours:minutes:seconds --> ua-cam.com/video/Xt0FCt-h66M/v-deo.htmlsi=88m-yJjQgM90Ztag Still using DAX for this analysis.

    • @bentatlim
      @bentatlim 3 місяці тому

      @@NestorAdrianzen Thank you for your video. Unfortunately, the format of the result in the video is not hh:mm:ss (for example 145:29:30) 😮‍💨

  • @yambhujel5511
    @yambhujel5511 Рік тому

    I tried this code but it is not summing up which is having more than 24 hours duration.

  • @giuseppefaleo9753
    @giuseppefaleo9753 2 роки тому

    Hi, If i don't want a format like d:hh:mm:ss but i'm looking for [h]:mm:ss so 89:20:53 there's something you can suggest?

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Giuseppe, Thanks checking the content out.
      DAX is weird! I'm going to work on a tutorial to solve this question.
      Having as a reference the code that used in the tutorial, just remove the third and fourth variables and add the following piece of code instead: VAR HoursTotal = DaysTotal*24. Don't touch the remaining variables!
      Finally in the RETURN piece, just use the following: FORMAT(HoursInt,"00")&"h, "&FORMAT(MinutesInt,"00")&"m, "&FORMAT(SecondsTotal,"00")&"s "
      The result should be 89h, 20m, 53s.
      I hope this helps!

  • @Aadya.Boutique642
    @Aadya.Boutique642 Рік тому

    How we can subtract two time column and get the value in hh:mm:ss

  • @Neon_willys
    @Neon_willys 2 роки тому +1

    Thanks for the great presentation. it helped me a lot to understand DAX.
    Subscribed too..👍
    I'd like to show a line chart of Average time in HH:MM:SS format, but i was not table to do it.
    I was thinking may be if there is anything can be done using DAX formula.
    Thanks in advance

    • @mateogigena
      @mateogigena 2 роки тому

      Please let me know if you find an answer! I´m looking for the same

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Akshay, Thanks for your support. For averages, you will need to use AVERAGEX instead of SUMX in the first variable. I hope this helps. Cheers!

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Mateo, Thanks for stopping by. Please see below the answer that I provided to Akshay. Cheers!

  • @sabkuchdhela191
    @sabkuchdhela191 3 роки тому +3

    i just want in hours and not in days. what shud be modified in the code?

    • @manoulomanoulo7
      @manoulomanoulo7 2 роки тому

      Hey Anubhav! Did you find the solution your problem? I have the same problem, I want to sum only in hours. Thanks.

    • @sabkuchdhela191
      @sabkuchdhela191 2 роки тому

      @@manoulomanoulo7 yes I did found one

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Hey folks, Thanks for checking the content out and sorry for not getting back to you sooner.
      I'm going to work on a tutorial to solve this question.
      In the meantime, having as a reference the code that I used in the tutorial, just remove the third and fourth variables and add the following piece of code instead: VAR HoursTotal = DaysTotal*24. Don't touch the remaining variables!
      Finally in the RETURN piece, just use the following: FORMAT(HoursInt,"00")&"h, "&FORMAT(MinutesInt,"00")&"m, "&FORMAT(SecondsTotal,"00")&"s "
      The result should be 89h, 20m, 53s.
      Cheers!

  • @renatoravenna1166
    @renatoravenna1166 4 місяці тому

    Thank you!

  • @manoulomanoulo7
    @manoulomanoulo7 2 роки тому

    Hey Nestor! nice video!
    Could you explain how we can sum hours, minutes and seconds on this format: (h::nn:ss, e.g 94:00 h instead of 3d, 22h)

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Alekos77, Thanks for stopping by. DAX is weird! I'm going to work on a tutorial to solve this question.
      Having as a reference the code that used in the tutorial, just remove the third and fourth variables and add the following piece of code instead: VAR HoursTotal = DaysTotal*24. Don't touch the remaining variables!
      Finally in the RETURN piece, just use the following: FORMAT(HoursInt,"00")&"h, "&FORMAT(MinutesInt,"00")&"m, "&FORMAT(SecondsTotal,"00")&"s "
      The result should be 89h, 20m, 53s.
      I hope this helps!

    • @panagiotistsirkas
      @panagiotistsirkas Рік тому

      ​@@NestorAdrianzenthank you very much for this tutorial. But in the scenario that we want to represent the total hours and not days as mentioned above, if we delete the third and four var, in the fifth var there is the HourInt , that we have already deleted above.

  • @SergioMLandaeta
    @SergioMLandaeta 5 місяців тому

    Gracias Brother!

  • @mikayilheybatov8696
    @mikayilheybatov8696 2 роки тому

    thanks for video. Maybe you can solve my isseu too. I got my total duration from two years, but this total duration is different then I navigate it in years.

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому +1

      Mikayil,
      Thanks for stopping by. Could you please provide more detail about what you are looking for? If you are dealing with dates, you should have a calendar table in your model and then use a date column from the calendar table to filter your data.

    • @mikayilheybatov8696
      @mikayilheybatov8696 2 роки тому

      @@NestorAdrianzen thank for feedback. I do have calendar table. But my total duration seems to be smaller than my results in years.That is the case

  • @lalitvarma9310
    @lalitvarma9310 2 роки тому

    Is it also possible to use this as a measure on graphs? I tried adding it to the groahs but it doesnt work.

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Lalit, Thanks for stopping by. For this particular case, a CARD and TABLE/MATRIX are the appropriate charts to represent this measure. I hope this helps. Cheers!

  • @venkatareddykummitha5863
    @venkatareddykummitha5863 2 роки тому

    Thank your Cooperation in learning Power bi. Namaste
    By the way I subscribed your channel

  • @NaeemShahzad_
    @NaeemShahzad_ Рік тому

    THANKS BRO, ITS QUITE HELPFUL

  • @don_johnson_vice
    @don_johnson_vice 2 роки тому

    Thanks much for the explanation!)

  • @kaushlendrasengar8852
    @kaushlendrasengar8852 8 місяців тому

    Thanks a lot brother

    • @NestorAdrianzen
      @NestorAdrianzen  7 місяців тому

      Glad you found the content helpful. Cheers!

  • @praveen2522
    @praveen2522 Рік тому

    Thanks a lot

  • @YKMysterious
    @YKMysterious Рік тому

    the Data outcome type of this measure is test, how to show graphs for that?

    • @NestorAdrianzen
      @NestorAdrianzen  Рік тому

      YKMysterious, Thanks for stopping by. One of the best visuals for this type of measures is a CARD, but you can also use a matrix/table.

  • @venkatareddykummitha5863
    @venkatareddykummitha5863 2 роки тому

    When I select a year a slicer I want to show all the before years values... In the table. How to Show any requirement by using the DAX.

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      venkatareddy, Thanks for stopping by. For previous year calculations, you might want to use the DATEADD function. This tutorial will help. Cheers! ua-cam.com/video/6vJIAJNTdG0/v-deo.html

  • @anilprnctube
    @anilprnctube 10 місяців тому

    Could you please share this Dax script please

  • @Robay146
    @Robay146 3 роки тому

    You're amazing! Thank you!

    • @NestorAdrianzen
      @NestorAdrianzen  3 роки тому

      Ro, Glad this tutorial was helpful. Keep 🆙 the good work👍

  • @kennethstephani692
    @kennethstephani692 2 роки тому

    Great video!!

  • @andrewalfred3473
    @andrewalfred3473 3 роки тому

    Can we create weekly bar graph and show 4 week trends showing avg time taken

    • @NestorAdrianzen
      @NestorAdrianzen  3 роки тому

      Andrew, Thanks for stopping by. Perhaps your are trying to find moving averages? If so, this tutorial might help. Cheers! ua-cam.com/video/jiQM93dmUek/v-deo.html

  • @eladiobardelli3001
    @eladiobardelli3001 3 роки тому

    Si tuvieras que sumar turnos que tengan turnos no consecutivos por operador ,como se podría anexar a tu formula ? Saludos desde Chile.

    • @NestorAdrianzen
      @NestorAdrianzen  3 роки тому

      Eladio, Gracias por revisar el contenido. El mecanismo a aplicar debe ser similar. Lo que es clave para este tipo de cálculos es entender bien los pasos y conversiones de tiempo. Saludos a los hermanos de la república de Chile👍

  • @ashishmohan4707
    @ashishmohan4707 3 роки тому

    Thanks for sharing with very useful tricks
    One suggestion if you can instead of alt_enter you can use shift+enter to create new line for DAX
    It will not create sound,, hope you understand
    Thanks again.
    But can you please help me out regarding one query
    e.g
    i have three number like
    300
    301
    301
    i need to create rank ,but i need to rank like below, means my required out put is
    Number rank
    300 1
    301 2
    301 3
    means i need to DAX for duplicate value
    kindly help me out for this .
    Thanks in advance.

    • @NestorAdrianzen
      @NestorAdrianzen  3 роки тому

      Excellent! Thanks for the trick, Ashish Mohan!

    • @ashishmohan4707
      @ashishmohan4707 3 роки тому

      @@NestorAdrianzen plzz can you solve this query

    • @ashishmohan4707
      @ashishmohan4707 3 роки тому

      @@NestorAdrianzen plzz can you solve this query

  • @TheFootyFever
    @TheFootyFever 2 роки тому

    genius! thank you

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Phil, I appreciate your support and keep up the good work!

    • @TheFootyFever
      @TheFootyFever 2 роки тому

      @@NestorAdrianzen no problem - I have searched for this answer in many places and no-one has approached the issue in this way - all of the other methods did not work so was thrilled to find your solution . Best regards - Boom!

  • @muhammadzarshid7628
    @muhammadzarshid7628 2 роки тому

    very nice appreciated

  • @rams5042
    @rams5042 2 роки тому

    Hi sir I do whatever you telling in the video but I got 29 hrs a day can u please help me in this

    • @rams5042
      @rams5042 2 роки тому

      NuWhen I'm applying filter it shows 29 hrs.but in that particular filtering having 8:30 hrs only can u please help me

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Rams, Thanks for stopping by. It's hard to tell why this is happening. My recommendation would be to start the exercise from zero again. I hope that helps!

    • @rams5042
      @rams5042 2 роки тому

      @@NestorAdrianzen ok sir are you applying the formula in hours type column or decimal type column in power bi dax

  • @ChocoHammer
    @ChocoHammer Рік тому

    It would be great, if I could use the sum of the hours, like make it into 199h20m05s and so on, because this is great, but I'm loosing againts the math in the report :D

  • @po3ta_zero
    @po3ta_zero 2 роки тому

    Amigo tienes este tuto en español? Este tema me tiene atado de manos 😭😭😭😭

    • @NestorAdrianzen
      @NestorAdrianzen  2 роки тому

      Qué tal Oscar. Lo siento. Solo lo tengo en inglés por ahora. Puedes activarle los subtítulos. Espero eso ayude. Saludos

    • @po3ta_zero
      @po3ta_zero 2 роки тому

      @@NestorAdrianzen gracias amigo, eso haré, un saludo!

  • @mohamedyoussef8367
    @mohamedyoussef8367 Місяць тому

    Our dear professor, can you send the equation as the video is not clear to me? Thank you❤

    • @NestorAdrianzen
      @NestorAdrianzen  Місяць тому

      Hey Mohamed, Thanks for stopping by. Could you please share an email with your questions at nestor@quipuanalytics.com. I'll do my best to guide you. Thanks.