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
Carlo1975
Helper I
Helper I

Find and Repeat Value

Hi, I have a table with 3 columns:

 

IdBuildingSingleTypePrice
1Residential120
1Commercial150
1Parking50
1Office55
2Hospital250
2Parking15
3Hotel1200
3Parking35
3Office25
3Commercial25

 

I have to add a new column. For each IDBuilding I have to insert in the new column the first value find in SingleType, like this:

 

IdBuildingSingleTypePriceBuilding Type
1Residential120Residential
1Commercial150Residential
1Parking50Residential
1Office55Residential
2Hospital250Hospital
2Parking15Hospital
3Hotel1200Hotel
3Parking35Hotel
3Office25Hotel
3Commercial25Hotel

 

and so for IdBuilding 1 I will write Residential on all the 4 row of ID 1, IdBuilding 2 I will write Hospital and 3 Hotel

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

This could be done in a DAX column if you first add an index, but here is one way to do it in the Query Editor.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kxxKs3MScnMS1fSUQoGUjmpIZUFqUBOQFFmcqpSrE60kiGQF5RanJmSmleSmZgD5BkaGcBlnPNzc1OLkqESpgiJgMSibIi5SIL+aWkgY4FipmAxIyDTI7+4ILMErN8IqtQIRb8hRK0xWG1JKtQFBnBBhEpjhEq4TUYIMRS3gsRjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"IdBuilding", Int64.Type}, {"SingleType", type text}, {"Price", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each let thisid = [IdBuilding] in List.First(Table.SelectRows(#"Changed Type1", each [IdBuilding] = thisid)[SingleType]), type text)

in
    #"Added Custom"

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

This could be done in a DAX column if you first add an index, but here is one way to do it in the Query Editor.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kxxKs3MScnMS1fSUQoGUjmpIZUFqUBOQFFmcqpSrE60kiGQF5RanJmSmleSmZgD5BkaGcBlnPNzc1OLkqESpgiJgMSibIi5SIL+aWkgY4FipmAxIyDTI7+4ILMErN8IqtQIRb8hRK0xWG1JKtQFBnBBhEpjhEq4TUYIMRS3gsRjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"IdBuilding", Int64.Type}, {"SingleType", type text}, {"Price", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each let thisid = [IdBuilding] in List.First(Table.SelectRows(#"Changed Type1", each [IdBuilding] = thisid)[SingleType]), type text)

in
    #"Added Custom"

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


No, I have wronged...I have problem also with power query if I refresh all the table (not only the first 1000 rows). I have totally 12.000 rows.

Hi Pat, your solution it's ok, but I have a problem, now the Power BI fails to load file. it is very slow, after 10 hours it still fails to update the data. Power Query functions, Power BI no. Have you any idea?

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.

Top Solution Authors