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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Create new integer column for text

Hi, I have this set of data, now i would like to derive a new column call age:

For YOB type is text, so im encounter problem to convert it to number. 

For new column Age it should be derive from '2024-YOB'

YOBAGE 
199034
19DC0
197252
198341
19DC0
19DC0
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

you can also try to use DAX to get the new column

 

AGE = IFERROR(2024-'Table'[YOB],0)
OR 
AGE = IFERROR(YEAR(TODAY())-'Table'[YOB],0)
11.PNG
 
 




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

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Anonymous
Not applicable

thank you!

ryan_mayu
Super User
Super User

@Anonymous 

you can also try to use DAX to get the new column

 

AGE = IFERROR(2024-'Table'[YOB],0)
OR 
AGE = IFERROR(YEAR(TODAY())-'Table'[YOB],0)
11.PNG
 
 




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

Proud to be a Super User!




Anonymous
Not applicable

thank you!

you are welcome





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

Proud to be a Super User!




rajendraongole1
Super User
Super User

Hi @Anonymous -you can add one new add column in power query editor as below:

 

rajendraongole1_0-1720594112048.png

 

if [YOB] = 0 then 0 else 2024 - [YOB]

 

you will have a new Age column derived from the YOB column, with invalid YOB values handled appropriately.

 

M code:

let
Source = Excel.Workbook(File.Contents("C:\Path\To\Your\File.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"YOB", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","19DC","0",Replacer.ReplaceText,{"YOB"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"YOB", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Age", each if [YOB] = 0 then 0 else 2024 - [YOB]),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom",{{"Age", Int64.Type}})
in
#"Changed Type2"

 

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!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.