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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
duesouth
Helper I
Helper I

Minor Change to a Formula - One Decimal Place for Date in Years/Months format

With help from this community, I've been working out how to change reading ages for pupils in a school into a years months format.  This is now done and working.  My one last thing - the icing on the cake - is that the formula below gives me a result in the format 12 Years 9.1764705882353 Months for our year 7 cohort.  Can the formula below be changed so that I can set to 1 decimal place?    The format of the column in Power BI is text - if I change it to a number I then get an error...

 

Reading Age Averaged =
var year1= INT('Reading Ages'[Average RA]/12)
var month1='Reading Ages'[Average RA]- year1*12
return
SWITCH( TRUE(),
    'Reading Ages'[Average RA]<12,"0 Year "& 'Reading Ages'[Average RA] & " Months",
    'Reading Ages'[Average RA]=12,"1 Year "& "0 Months",
    year1& " Years " & month1 & " Months")
 
Thanks in advance for any help!
1 ACCEPTED SOLUTION
aduguid
Super User
Super User

Reading Age Averaged =
VAR year1 = INT('Reading Ages'[Average RA] / 12)
VAR month1 = 'Reading Ages'[Average RA] - year1 * 12
RETURN
    SWITCH(
        TRUE(),
        'Reading Ages'[Average RA] < 12, "0 Year " & FORMAT('Reading Ages'[Average RA], "0.0") & " Months",
        'Reading Ages'[Average RA] = 12, "1 Year 0 Months",
        year1 & " Years " & FORMAT(month1, "0.0") & " Months"
    )

View solution in original post

3 REPLIES 3
aduguid
Super User
Super User

Reading Age Averaged =
VAR year1 = INT('Reading Ages'[Average RA] / 12)
VAR month1 = 'Reading Ages'[Average RA] - year1 * 12
RETURN
    SWITCH(
        TRUE(),
        'Reading Ages'[Average RA] < 12, "0 Year " & FORMAT('Reading Ages'[Average RA], "0.0") & " Months",
        'Reading Ages'[Average RA] = 12, "1 Year 0 Months",
        year1 & " Years " & FORMAT(month1, "0.0") & " Months"
    )
rajendraongole1
Super User
Super User

Hi @duesouth - Can you try the below updated measure:

Reading Age Averaged =
var year1 = INT('Reading Ages'[Average RA] / 12)
var month1 = ROUND('Reading Ages'[Average RA] - year1 * 12, 1)
return
SWITCH(
TRUE(),
'Reading Ages'[Average RA] < 12, "0 Year " & month1 & " Months",
'Reading Ages'[Average RA] = 12, "1 Year 0 Months",
year1 & " Years " & month1 & " Months"
)

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





@aduguid @rajendraongole1 Thank you so much for your help - much appreciated!

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.