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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
BCWdesign
Frequent Visitor

Convert months into years and months

 

Hi

I hope someone can help

I have a column in powerbi which shows months

E.g 18 months

I want a formulae to create a column which converts this to years and months

E.g 1 year 6 months

 

Hopefully this can be achieved with a simple measure 

1 ACCEPTED SOLUTION
mukeshkasi25
Frequent Visitor

Hi @BCWdesign 
Please try this 

 

mukeshkasi25_0-1690960492518.png

 

View solution in original post

5 REPLIES 5
mukeshkasi25
Frequent Visitor

Hi @BCWdesign 
Please try this 

 

mukeshkasi25_0-1690960492518.png

 

grazitti_sapna
Super User
Super User

Hi @BCWdesign ,

You can try using:-

convert into year = 
VAR _year = INT([Value]/12)
VAR _Month = [Value]-_year*12
RETURN
SWITCH(
TRUE(),
[Value] < 12,"0 Year, " & [Value] & " Month",
[Value] =12 ,"1 Year, " & "0 Month",
_year &" Year, " &_Month & " Month")

 

Thank you.

Hope this will help you.

Ahmedx
Super User
Super User

pls try this

 

Column = 
VAR _year = INT([Value]/12)
VAR _Month = [Value]-_year*12
RETURN
SWITCH(
    TRUE(),
    [Value] < 12,"0 Year, " & [Value] & " Month",
    [Value] =12 ,"1 Year, " & "0 Month",
    _year &" Year, " &_Month & " Month")

 

Screenshot_4.png

DOLEARY85
Resident Rockstar
Resident Rockstar

Additionally this can be done in power query and then it doesn't matter if you have the word months in the original field or just the number. you can just use the below in a custome column:

 

if Number.RoundDown([Custom]/12) <> 0 then

Number.ToText(Number.RoundDown([Custom]/12)) & " " & "Years" & " " &

Number.ToText(Number.Mod([Custom],12))& " " & "Months" else Number.ToText(Number.Mod([Custom],12)) & " " & "Months"

 

DOLEARY85_0-1690920932329.png

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

DOLEARY85
Resident Rockstar
Resident Rockstar

Hi,

 

provided the original months column field is just a number you can use:

 

Column = VAR _year =
    ROUNDDOWN ( DIVIDE ( 'Table (2)'[Column1], 12 ), 0 )
RETURN
    IF (
        _year <> 0,
        _year & " Year "
            & MOD ( 'Table (2)'[Column1], 12 ) & " Months",
        MOD ( 'Table (2)'[Column1], 12 ) & " Months"
    )
 
If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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