Skip to main content

How to Get the Remainder of a Division in Power Apps with Mod

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Mod returns what's left over after a division. Mod(450, 60) is 30: 450 minutes is seven whole hours with 30 minutes left over. Together with RoundDown for the whole hours, it turns a number of minutes into hours and minutes.

The example is the Overtime Timesheet app, which shows the hours of each shift as, for example, 7 h 30 min.

Syntax​

Syntax
Mod(Number, Divisor)
  • Number is the number to divide, and Divisor the number to divide by.
  • The result has the same sign as the divisor (Mod function).

Microsoft's examples:

FormulaResult
Mod(25, 4)1
Mod(25, -4)-3
Mod(-25, -4)-1
Mod(-25, 4)3

Step 1: Get the Minutes Left Over​

I put the formula into a text control's Text for a moment, so Studio's preview strip shows the result:

Any text control → Text
Mod(450, 60)

450 divided by 60 is 7, with 30 left over:

The formula bar with Mod(450, 60), the preview strip reading 30 with Data type number, and the text control on the Log overtime screen showing 30

Step 2: Pair It with the Whole Hours​

Mod gives only the part left over. The whole hours come from dividing and rounding down: RoundDown(450 / 60, 0) is 7 (How to Round a Number in Power Apps with Round, RoundDown and RoundUp). Together they make 7 h 30 min: How to Convert Minutes to Hours and Minutes in Power Apps.

How the Example Uses It​

The app uses Mod twice.

The hours line on the Log overtime screen splits the minutes worked:

Part of lblHoursLO → Text
$"Hours worked: {Text(Minutes / 60, "0.00")} ({RoundDown(Minutes / 60, 0)} h {Mod(Minutes, 60)} min)"

And the list of times people pick from turns a number of minutes since midnight into a time of day: the hour from RoundDown, the minute from Mod (How to Let Users Pick a Time in Power Apps):

App → Formulas
TimeChoices = ForAll(Sequence(288, 0, 5), Time(RoundDown(Value / 60, 0), Mod(Value, 60), 0));

Common Mistakes​

MistakeWhat happensDo this instead
Using Mod for the whole hoursYou get the minutes left over, not the hoursRoundDown(minutes / 60, 0) for the hours
Swapping the argumentsThe divisor becomes the number being dividedThe number first, the divisor second
Expecting a negative result for a negative numberThe sign follows the divisor: Mod(-25, 4) is 3Keep the minutes 0 or more, for example with Max(0, …)

Troubleshooting​

SymptomLikely causeFix
The minutes are larger than 59The divisor isn't 60Mod(minutes, 60)
The minutes look wrong for a negative totalMod follows the divisor's signStop the total going below 0 before splitting it

FAQ​

Does Excel have the same function?​

Yes, MOD. The old Excel timesheet the app replaces used it to wrap overnight shifts round the clock: How to Calculate Hours for an Overnight Shift in Excel with MOD.

How do I check whether a number is even?​

Mod(n, 2) = 0 is true when n divides by 2 with nothing left over.

Conclusion​

Mod(Number, Divisor) is what's left after dividing. With 60 as the divisor it's the minutes past the whole hours, and with RoundDown for the hours it splits any number of minutes.

Additional Resources​