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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Custom Dimension Table in Desktop. Need help with code. All assitance appreciated

Hi all, 

 

I need to create a dimension table to build a relationship. The issue is very specific. Please see below. 

 

I have this list:

 

 

What I haveWhat I have

 

 

 

 

 

 

What I need: 

What I need.pngAs you can see. It is the first list duplicated (12 times, one for each month). Then I need to add month, year up until 2025, and two columns with a code to be used to create a unique ID.. 

 

 

 

 

 

 

 

 

 

 

 

 

Could someone help me out with this?

 

Thank you! 🙂

 

Best regards

 

Morten

 

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

You can use the M code below, to create your table in Query Eritor.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjMxM7GwMFPSUTIEYiOlWJ1oJRNDYwszFzcUsYgQEzNTExQhN0c3oBC6qIWJhbkFQiQWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Account = _t, Type1 = _t, Type2 = _t]),
    #"Added Custom" = Table.AddColumn(Source, "MonthNo", each {1..12}),
    #"Expanded Month" = Table.ExpandListColumn(#"Added Custom", "MonthNo"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Month", "Year", each {2019..2025}),
    #"Expanded Year" = Table.ExpandListColumn(#"Added Custom1", "Year"),
    #"Added Custom2" = Table.AddColumn(#"Expanded Year", "Month", each Text.Start( Date.MonthName( #date([Year], [MonthNo], 1)), 3)),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom2",{{"MonthNo", Int64.Type}, {"Year", Int64.Type}, {"Month", type text}})
in
    #"Changed Type"


Regards,
Mariusz

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


View solution in original post

2 REPLIES 2
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

You can use the M code below, to create your table in Query Eritor.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjMxM7GwMFPSUTIEYiOlWJ1oJRNDYwszFzcUsYgQEzNTExQhN0c3oBC6qIWJhbkFQiQWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Account = _t, Type1 = _t, Type2 = _t]),
    #"Added Custom" = Table.AddColumn(Source, "MonthNo", each {1..12}),
    #"Expanded Month" = Table.ExpandListColumn(#"Added Custom", "MonthNo"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Month", "Year", each {2019..2025}),
    #"Expanded Year" = Table.ExpandListColumn(#"Added Custom1", "Year"),
    #"Added Custom2" = Table.AddColumn(#"Expanded Year", "Month", each Text.Start( Date.MonthName( #date([Year], [MonthNo], 1)), 3)),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom2",{{"MonthNo", Int64.Type}, {"Year", Int64.Type}, {"Month", type text}})
in
    #"Changed Type"


Regards,
Mariusz

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


Anonymous
Not applicable

Amazing speed and accuracy of your reply. Thanks a heap, worked like a charm 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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