Forum Discussion

LFrench's avatar
LFrench
Frequent Visitor
1 year ago
Solved

VARIABLE should default to "0"

I'm working on taking a count of minutes, and breaking it into days, hours and minutes. I got the majority of the DAX coding working, but if the minutes is exactly an hour (60 minutes, 120 minutes, e...
  • Deku's avatar
    1 year ago
    Course Time =
    VAR TotalMinutes =      SUM( 'Course Information'[MIN] )
    VAR TotalDays =         DIVIDE( TotalMinutes, 1440, 0)
    var days =              INT( TotalDays )
    Var remainingHours =    MOD( COALESCE( TotalDays,0 ), 1 ) * 24
    Var hours =             INT( remainingHours )
    Var remainingMins =     MOD( COALESCE( remaingHours, 0 ), 1 ) * 60
    Var mins =              INT( min )
    Return
    If( days > 0,  days & " days " ) &
    If( hours > 0, hours & " hours ") &
    If( mins > 0,  mins & " minutes")
    
  • ValtteriN's avatar
    1 year ago

    Hi,

    While the if logic will also work you can easily do something like this:

    Measure 33 =
    var TotalMinutes = MAX('Table (52)'[Column1])
    var TotalSeconds = TotalMinutes*60
    VAR Hours = INT(TotalSeconds / 3600)
    var minutes = TotalMinutes-Hours*60
    RETURN

    "hours "&Hours& " minutes "&minutes

     

    I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

    My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/