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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mariaoye
Regular Visitor

age range in text to age range in whole numbers

Hi,

 

Please I need help with changing age range in text to numbers on Power BI desktop.

 

The aage column has the following sample ranges:

 

Total - Age

15 to 24 years

25 to 29 years

 

I replacec the first "Total - Age" to "0-100" so I can convert the others to numbers. It gave errors. I replaced the "to" into "-".

I replaced "years" with " ". I then tried changing the data type to whole number.  It still gave errors. How do I then chenge the column from text type to whole numbers?

 

Thank you.

7 REPLIES 7
amitchandak
Super User
Super User

@Mariaoye , what is the expected output.

You can have a column like

Switch( True(),

[Total - Age] = "Total - Age" , 0,

left([Age],2)

)

or

left([Age], search(" ",[Age],1,0) -1)

 

 

jthomson
Solution Sage
Solution Sage

What number do you want exactly? If it's just some number in the range, can you not just extract the first two characters of the field?

Thanks for your response. I want to have a range in numbers that I can use to plot graphs. This is a dataset I got about income and I just want to plot the incomes based on the age ranges.

 

15-24

25-34.....

 

 

Hi @Mariaoye ,

 

If your expected output is 15-24, 25-34, etc., then how is it going to be whole number? This will always be text datatype.

Also, you can also create groups based on the Age. Right click on age field and create new group.

 

Give a thumbs up if this post helped you in any way and mark this post as solution if it solved your query !!!

 

 

@Anand24 Thanks. I guess I was looking at it all wrong.

I can only create categorical fields with range and not numeric. I want to believe that is what you meant.

 

Cheers.

@Mariaoye,
Yes, that's exactly what i meant. Your range can never be in whole number format.

@jthomson 

Thanks for your response. I want to have a range in numbers that I can use to plot graphs. This is a dataset I got about income and I just want to plot the incomes based on the age ranges.

 

15-24

25-34....

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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