Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Hi,
I need to calculate the birthday of the people in my dataset from their social security number. This is a 10-digit number where the first 6 digits date of birth. for example, 051289XXXX would be 5th of December and (probably) 1989.
However because only 2 digits are used to describe year, I need to use the following 4 digits to determine century of birth.
This can be determined as follows
In excel I would do something like this. But how do is express this in PowerBi advanced editor?
Public Function CprToDato(cpr As String) As Date
Dim bytCent As Byte
Dim bytSevdig As Byte
Dim bytCprYear As String
If Not IsNull(cpr) Then
bytSevdig = Mid(cpr, 8, 1)
bytCprYear = Mid(cpr, 5, 2)
Select Case bytSevdig
Case 0 To 3
bytCent = 19
Case 4, 9
If bytCprYear <= 36 Then
bytCent = 20
Else
bytCent = 19
End If
Case 5 To 8
If bytCprYear <= 36 Then
bytCent = 20
ElseIf bytCprYear >= 58 Then
bytCent = 18
End If
End Select
CprToDato = Left(cpr, 2) & "-" & Mid(cpr, 3, 2) & "-" & bytCent & bytCprYear
End If
End Function
Thanks!
Solved! Go to Solution.
check this.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjA1NLKwNI2IiFCKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"social security number" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"social security number", type text}}),
#"Extract Day" = Table.AddColumn(#"Changed Type", "Day", each Number.FromText(Text.Start([social security number], 2)), type number),
#"Extract Month" = Table.AddColumn(#"Extract Day", "Month", each Number.FromText(Text.Middle([social security number], 2, 2)), type number),
#"Extract Year" = Table.AddColumn(#"Extract Month", "Year", each Number.FromText(Text.Middle([social security number], 4, 2)), type number),
#"7th" = Table.AddColumn(#"Extract Year", "7th", each Number.FromText(Text.Middle([social security number], 6, 1)), type number),
Century = Table.AddColumn(#"7th", "century", each if [7th] <= 3
then 1900
else if ([7th] = 4 or [7th] = 9) and [Year] <= 36
then 2000
else if ([7th] = 4 or [7th] = 9) and [Year] > 36
then 1900
else if ([7th] = 5 or [7th] = 😎 and [Year] <= 36
then 2000
else if ([7th] = 5 or [7th] = 😎 and [Year] >= 58
then 1800
else 0, type number),
Birthdate = Table.AddColumn(Century, "Birthdate", each #date([century]+[Year],[Month],[Day]), type date)
in
Birthdate
Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials
check this.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjA1NLKwNI2IiFCKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"social security number" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"social security number", type text}}),
#"Extract Day" = Table.AddColumn(#"Changed Type", "Day", each Number.FromText(Text.Start([social security number], 2)), type number),
#"Extract Month" = Table.AddColumn(#"Extract Day", "Month", each Number.FromText(Text.Middle([social security number], 2, 2)), type number),
#"Extract Year" = Table.AddColumn(#"Extract Month", "Year", each Number.FromText(Text.Middle([social security number], 4, 2)), type number),
#"7th" = Table.AddColumn(#"Extract Year", "7th", each Number.FromText(Text.Middle([social security number], 6, 1)), type number),
Century = Table.AddColumn(#"7th", "century", each if [7th] <= 3
then 1900
else if ([7th] = 4 or [7th] = 9) and [Year] <= 36
then 2000
else if ([7th] = 4 or [7th] = 9) and [Year] > 36
then 1900
else if ([7th] = 5 or [7th] = 😎 and [Year] <= 36
then 2000
else if ([7th] = 5 or [7th] = 😎 and [Year] >= 58
then 1800
else 0, type number),
Birthdate = Table.AddColumn(Century, "Birthdate", each #date([century]+[Year],[Month],[Day]), type date)
in
Birthdate
Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials
565-21-3304
Thank you! This solved my problem.
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 57 | |
| 53 | |
| 40 | |
| 17 | |
| 16 |
| User | Count |
|---|---|
| 116 | |
| 105 | |
| 41 | |
| 34 | |
| 25 |