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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Shorting an Alphanumeric column

I have a column in my data base and data type of the column is varchar.

Column data are like:

1 year

3 days

11 hours

2 months

 

I want to short the data like below:

11 hours

3 days

2 MONTHS

1 YEAR

 

BUT I am not able to do so?

  • Can anyone please help me out?15971729627155741650008667355376.jpg

6 REPLIES 6
Anonymous
Not applicable

HI @Anonymous This might be achievable but you will need to do some data cleanup and transformation inside power query editor and then create a custom function within power query.

 

Can you share some sample data?

 

Thanks

FarhanAhmed
Community Champion
Community Champion

What you can do is to create a custom column in power query that will extract your number and convert it to minutes

if 
Text.Contains([Column1],"hours") then Number.FromText( Text.Replace([Column1],"hours","")) * 60
else if
Text.Contains([Column1],"days") then Number.FromText( Text.Replace([Column1],"days","")) * 24 * 60
else if
Text.Contains([Column1],"Months") then Number.FromText( Text.Replace([Column1],"Months","")) * 30 * 24 * 60
else if
Text.Contains([Column1],"year") then Number.FromText( Text.Replace([Column1],"year","")) *12*30*24* 60
else 
0

 

Then convert this value column to "WholeNumber"

After that sort your Alphanumeric column with this value number that will sort your data as desired. 

SortAlphanumeric.png







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

Proud to be a Super User!




Anonymous
Not applicable

Hello

  • I have created a column. And Sorted as per your suggestion, But I don't know why it's not getting sorted. IMG_20200812_145732.jpg

Anonymous
Not applicable

Hi @Anonymous 

 

You have to use the new created column in the chart on the intial screenshot shared and sort on that column.

 

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

Regards,
Pranit

 

Anonymous
Not applicable

Hi @Anonymous 

 

There is no easy way in which this data can be sorted as there is no datatype which can identify it. I am not saying it is impossible.

 

One possible and easy solution can be to create a calculated column on the WorkItem_id table created_date column and display it as one unit

Age in Months = DATEDIFF(created_date,today(), MONTH)

Alternatively you can also display it in week, day or hour
Age in Months = DATEDIFF(created_date,today(), WEEK)
Age in Months = DATEDIFF(created_date,today(), DAY)
Age in Months = DATEDIFF(created_date,today(), HOUR)

 

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

Regards,
Pranit

v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Not certain what is your expected output based on your picrture and description. Could you please consider sharing some sample data and expected output for further discussion?

Sample data and expected output would help tremendously.
Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors