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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
LFrench
Frequent Visitor

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, etc), the 'Total Minutes' VAR is blank, so the result is "1 Hour, Minutes." How can I default VAR Total Minutes to "0" if it is exactly an hour.

Course Time =
VAR TotalMinutes = SUM('Course Information'[MIN])
VAR TotalHours = TotalMinutes/60
VAR TotalDays = TotalHours/24
VAR Hours = INT(TotalHours)
VAR Minutes = MOD(TotalHours,1)*60
VAR Days = INT(TotalDays)
2 ACCEPTED SOLUTIONS
Deku
Super User
Super User

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")

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

ValtteriN
Super User
Super User

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
ValtteriN_0-1742664079882.png

 

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/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ValtteriN
Super User
Super User

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
ValtteriN_0-1742664079882.png

 

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/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Deku
Super User
Super User

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")

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Misread the request just use

 

COALESCE( minutes, 0)

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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