The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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.
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