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
UmairKamal
Helper I
Helper I

converting the number of days into months

Dear Users,

 

I have two dates in a dataset, and i have created another column showing the difference in the number of days between these two dates. I would like the number of days to be represented as months.

 

for example, the first row shows 271 days, i would like to show this as 8.9 in months.

 

your help will be appreciated.

1 REPLY 1
jennratten
Super User
Super User

Hello - this will return the number of months as a whole number.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJW0lEyNNI3grBjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start", type date}, {"End", type date}}),
    date_diff = Table.AddColumn(
                // starting table
            #"Changed Type",
            // name of new column to be created
            "DurationInMonths", 
            each 
                // declare inline variables
                let 
                    // calculate the compelete years elapsed
                    DateDiffInYears = 
                        Date.Year ( [End] ) - Date.Year ( [Start] ),
                    // calculate the remaining months
                    MonthsRemaining = 
                        Date.Month ( [End] ) - Date.Month ( [Start] ),
                    // calculate the total number of months
                    DateDiffInMonths = 
                        ( DateDiffInYears * 12 ) + MonthsRemaining
                in
                    DateDiffInMonths,
                    Int64.Type
    )
in
    date_diff

jennratten_0-1679331644725.png

 

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.

Top Solution Authors