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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
nbcholst
Frequent Visitor

Is it possible to create a table based on combining two columns

Hi All,

 

I have a table that has a list of Items - A,B,C, etc.

 

I also have a table that has a value matched to each item. So A = 3, B = 4, C = 2, etc.

 

I want to create a table of unique Letter - Value combinations, where the Letter is matched to increments of 1 up until the Value, so the rows look like this:

A1

A2

A3

B1

B2

B3

B4

C1

C1

 

Is this possible in PowerBI? What's the best way to create something like this without manually creating a table in Excel?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

You only need one table to solve this problem - the second one.  You will have to use the following M code in Power Query

 

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Items", type text}, {"Repeat till", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Start from", each 1),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Items", "Start from", "Repeat till"}),
    #"Added Custom1" = Table.AddColumn(#"Reordered Columns", "Custom", each { Number.From([Start from])..Number.From([Repeat till]) }),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Start from", "Repeat till"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Custom", type text}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom.1", each [Items]&[Custom]),
    #"Renamed Columns" = Table.RenameColumns(#"Added Custom2",{{"Custom.1", "Result"}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns",{"Items", "Custom"})
in
    #"Removed Columns1"

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

1 REPLY 1
Ashish_Mathur
Super User
Super User

Hi,

 

You only need one table to solve this problem - the second one.  You will have to use the following M code in Power Query

 

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Items", type text}, {"Repeat till", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Start from", each 1),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Items", "Start from", "Repeat till"}),
    #"Added Custom1" = Table.AddColumn(#"Reordered Columns", "Custom", each { Number.From([Start from])..Number.From([Repeat till]) }),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Start from", "Repeat till"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Custom", type text}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom.1", each [Items]&[Custom]),
    #"Renamed Columns" = Table.RenameColumns(#"Added Custom2",{{"Custom.1", "Result"}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns",{"Items", "Custom"})
in
    #"Removed Columns1"

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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