- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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'
YOB | AGE |
1990 | 34 |
19DC | 0 |
1972 | 52 |
1983 | 41 |
19DC | 0 |
19DC | 0 |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@Anonymous
you can also try to use DAX to get the new column
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@Anonymous
you can also try to use DAX to get the new column
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

you are welcome
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @Anonymous -you can add one new add column in power query editor as below:
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!!
Proud to be a Super User! | |

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
05-15-2024 11:29 AM | |||
05-12-2024 07:50 AM | |||
07-01-2024 10:29 AM | |||
10-11-2024 12:20 PM | |||
08-20-2024 08:44 AM |
User | Count |
---|---|
117 | |
99 | |
84 | |
53 | |
47 |