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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Custom column based on ranking

I need to create a new column called tech_id_padu in the below example.  I need the column to take the highest rank for each askID and return the rating.  I'm not sure how to write the logic for this.  I'm assuming I need to create a custom column and write some code to get this to work.

 

griffinst_0-1655142934297.png

 

4 REPLIES 4
Anonymous
Not applicable

Here's some sample data.  I wasn't able to get it working.  I filled in the tech_id_padu column with what the custom column should display.  Thanks

askId	aggregateTechPaduRating	softwareName	rating	tech_ld_rank	tech_id_padu
U006626	Discouraged	Anacron	NotRated	0	Unacceptable
U006626	Discouraged	Apache Ant	Discouraged	3	Unacceptable
U006626	Discouraged	Chef	Preferred	1	Unacceptable
U006626	Discouraged	Firewall	Preferred	1	Unacceptable
U006626	Discouraged	Foomatic	NotRated	0	Unacceptable
U006626	Discouraged	IBM Business Process Manager Advanced	Acceptable	2	Unacceptable
U006626	Discouraged	IBM Global Security Kit	NotRated	0	Unacceptable
U006626	Discouraged	IBM JDK	Unacceptable	4	Unacceptable
U006626	Discouraged	IBM WebSphere Application Server	Discouraged	3	Unacceptable
U006626	Discouraged	IBM WebSphere Enterprise Service Bus - ESB	Unacceptable	4	Unacceptable
U006626	Discouraged	IPT	Acceptable	2	Unacceptable
U006626	Discouraged	Red Hat JBoss EAP	Acceptable	2	Unacceptable
U018813	Discouraged	Anacron	NotRated	0	Discouraged
U018813	Discouraged	Apache Lucene	NotRated	0	Discouraged
U018813	Discouraged	Apache Tomcat	Preferred	1	Discouraged
U018813	Discouraged	CMSutil	NotRated	0	Discouraged
U018813	Discouraged	Chef	Preferred	1	Discouraged
U018813	Discouraged	Finger	NotRated	0	Discouraged
U018813	Discouraged	Firewall	Preferred	1	Discouraged
U018813	Discouraged	FxLoad	NotRated	0	Discouraged
U018813	Discouraged	Mootools	Discouraged	3	Discouraged

Hi @Anonymous ,

 

Thank you for sharing the data!

 

Here a solution:

tomfox_0-1655314607519.png

 

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZTJbsIwEEB/xco5lViqiGvC0hZIFRFQD4iD4wxgyXiiiUPbv68Jh5aWogQfLC/jeR7Ptl57q04nCHqB53sjWQqsiO8gt7tQc0Go7eoVzYKb+rBjx8oKBBSGZwq8jX+DUHCxBxZq80fUb8MZ7mFrp4RgC0T1UbeN/kQSvHOlnBiIB26kcHDHSxSzqCqlhrJkCaE4zTHXVkwszI9ci7PbvnG+12v7wpPCjCuWgqhImk82k8bR5ulo9lvF9x7bUt4gS4s9kM2HolBSWGeitmbSEcgtPS7pY22ACpIl1HApgD2c3M7GaeT6jWTpFJ4F5OyZGzbN0EZ+HCYNad3BoNtvXp8/r90EnMtzXgnQ4IxZ4sHG9EqJNeUM47QyUt1vyD9toqn6ROpdnYp3Pn+jyzRGfMyR5/ebECMaRFVeracLyOYL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [askId = _t, aggregateTechPaduRating = _t, softwareName = _t, rating = _t, tech_ld_rank = _t, tech_id_padu = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"askId", type text}, {"aggregateTechPaduRating", type text}, {"softwareName", type text}, {"rating", type text}, {"tech_ld_rank", Int64.Type}, {"tech_id_padu", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"askId"}, {{"MaxTechIDRank", each List.Max([tech_ld_rank]), type nullable number}, {"Rating", each _, type table [askId=nullable text, aggregateTechPaduRating=nullable text, softwareName=nullable text, rating=nullable text, tech_ld_rank=nullable number, tech_id_padu=nullable text]}}),
    #"Expanded Rating" = Table.ExpandTableColumn(#"Grouped Rows", "Rating", {"rating", "tech_ld_rank"}, {"Rating.rating", "Rating.tech_ld_rank"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Rating", "FilterColumn", each if [MaxTechIDRank] = [Rating.tech_ld_rank] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([FilterColumn] = 1)),
    #"Removed Duplicates" = Table.Distinct(#"Filtered Rows"),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"askId"}, #"Removed Duplicates", {"askId"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Rating.rating"}, {"Grouped Rows.Rating.rating"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Grouped Rows",{{"Grouped Rows.Rating.rating", "tech_id_padu_tomsCol"}})
in
    #"Renamed Columns"

 

Let me know if this helps 🙂


/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

askIDsoftwareratingtech_Id_ranktech_id_padu
U006626FoomaticAcceptable2Unacceptable
U006626IBM JDKUnacceptable4Unacceptable
U018813FirewallPreferred1Discouraged
U018813MootoolsDiscouraged3Discouraged
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

I'd suggest to do a grouping on askId with MAX tech_id_rank. Then join the result set with the original one and you should be good to go.

 

You may share some sample data or the file and I can support you further 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors