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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply

Create a calculated Brand_Id Column based on the brand name found in the row.

I have given below table:

ashishoza12345_1-1636520041536.png

I have to create a brand_id for each individual Brand as given below:

 

ashishoza12345_2-1636520149140.png

 

Please help!

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @ashishoza12345 

 

Download sample PBIX file

 

How many branbds do you have to do this for?  If it's not many you can set up a record to hold the Brand and Brand ID pairs.  Then use this query

 

let
    Brand_ID = [#"Honda" = 1, #"Suzuki" = 2, #"Ford" = 3, #"Toyota" = 4],
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sjPS0lUitWJVgourSrNzgQz3fKLUsCMkPzK/BKINEIhhmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Brand = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Brand", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Brand ID", each Record.Field(Brand_ID, [Brand]))
in
    #"Added Custom"

 

brands.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @ashishoza12345 ,

Here are the steps you can follow:

1. In Power query, Add Column – Index Column From 1.

vyangliumsft_0-1636680516781.png

2. Create calculated column.

Flag =
RANKX(FILTER(ALL('Table'),'Table'[Brand]=EARLIER('Table'[Brand])),[Index],,ASC)
Brand_ID =
var _id=CALCULATE(MAX('Table'[Index]),FILTER(ALL('Table'),[Flag]=1&&[Brand]=EARLIER('Table'[Brand])))
return
IF([Flag]=1,[Index],_id)

3. Result:

vyangliumsft_1-1636680516783.png

 

Best Regards,

Liu Yang

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

PhilipTreacy
Super User
Super User

Hi @ashishoza12345 

 

Download sample PBIX file

 

How many branbds do you have to do this for?  If it's not many you can set up a record to hold the Brand and Brand ID pairs.  Then use this query

 

let
    Brand_ID = [#"Honda" = 1, #"Suzuki" = 2, #"Ford" = 3, #"Toyota" = 4],
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sjPS0lUitWJVgourSrNzgQz3fKLUsCMkPzK/BKINEIhhmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Brand = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Brand", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Brand ID", each Record.Field(Brand_ID, [Brand]))
in
    #"Added Custom"

 

brands.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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