Canvas Apps UDFs - udfCalculateDurationInMonths
Fractional Month Calculations Without the Guesswork - Canvas Apps UDF snippet just for you!
Fractional Month Calculations Without the Guesswork - Canvas Apps UDF snippet just for you!
Problem:
Canvas Apps gives you DateDiff in whole months only. As soon as your business logic requires partial months (for billing, proration, contracts, or SLAs), formulas quickly become inconsistent and ugly across your apps.
Thatβs where a reusable UDF saves you.
What it does:
π Calculates duration between two dates in fractional months
π Accounts for different month lengths (28β31 days)
π Rounds the result to 2 decimal places
π Works consistently across year and month boundaries
Examples:
π
2026-02-01 β 2026-02-08 (1 week from 28-day month) = 0.25 π
π
2026-03-01 β 2026-02-08 (1 week from 31-day month) = 0.23 π
π
2026-02-01 β 2026-02-15 (2 weeks from 28-day month) = 0.5 π
π
2026-02-01 β 2026-03-02 (full month and 1 day from 31-day month) = 1.03 π
Why this belongs in a UDF:
π Accuracy: no βaverage month = 30 daysβ shortcuts
π Reusability: one function for pricing, reporting, and validation
π Readability: replace a multi-line formula with a single function call
π Maintainability: adjust logic once, fix it everywhere
Typical use cases:
βοΈ Subscription proration
βοΈ Contract duration calculations
βοΈ Financial or SLA reporting
βοΈ Any scenario where partial months actually matter
As with other non-behavioural logic, this function fits perfectly into App.Formulas for Canvas Apps. Would you like to use it in your app?
π Leave a reaction and use the link from the comments section! π
___
π Get snippet code: https://github.com/jan-chlebek/Power-Platform-Snippets/blob/main/udf-canvas-apps/source/udfCalculateDurationInMonths.yaml
Browse articles