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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jona4k
Frequent Visitor

how to select specific rows in PowerQuery

Hey there,

I would like to use the PowerQuery Language to select for each [PRODUCT_ID] the max([SELL_AMOUNT]) 

the Table Name is TABLE

 

Any Suggestions?

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @jona4k 

If you start with data like this

sell-prices.png

 

you can Group By and choose Max as the Operation(Aggregation)

max-sell.png

 

resulting in this

max-sell-res.png

 

Copy/paste this code into a blank query

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0UIrVgTCN4SxDIzDTCMg0hbMMjRFMMzDTGMg0MoYzobqMoQpiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PRODUCT_ID = _t, SELL_AMOUNT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PRODUCT_ID", Int64.Type}, {"SELL_AMOUNT", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"PRODUCT_ID"}, {{"MAX_SELL_AMOUNT", each List.Max([SELL_AMOUNT]), type nullable number}})
in
    #"Grouped Rows"

 

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



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

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @jona4k,

I think PhilipTreacy 's suggestion should help for your scenario.
If his formula suitable for your requirement, you can consider accept it to help other user who faced the same issue find it quickly. If not , you can post here with detailed informations.
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
PhilipTreacy
Super User
Super User

Hi @jona4k 

If you start with data like this

sell-prices.png

 

you can Group By and choose Max as the Operation(Aggregation)

max-sell.png

 

resulting in this

max-sell-res.png

 

Copy/paste this code into a blank query

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0UIrVgTCN4SxDIzDTCMg0hbMMjRFMMzDTGMg0MoYzobqMoQpiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PRODUCT_ID = _t, SELL_AMOUNT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PRODUCT_ID", Int64.Type}, {"SELL_AMOUNT", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"PRODUCT_ID"}, {{"MAX_SELL_AMOUNT", each List.Max([SELL_AMOUNT]), type nullable number}})
in
    #"Grouped Rows"

 

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



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!


Anand24
Super User
Super User

Hi @jona4k ,

 

You can use below DAX in a new column:
Col = CALCULATE(MAX(Table[SELL_AMOUNT]), ALLEXCEPT(Table,Table[PRODUCT_ID]))

 

Give a thumbs up if this post helped you in any way and mark this post as solution if it solved your query !!!

I know how its done in DAX, but I specifically want to do it before implementing the table. Furthermore I need only the single rows with the max(amount) from the table, but all other Columns as well So I'm basically loking for a Filter which only returns the rows including the max(amount) for each PRODUCT_ID

PhilipTreacy
Super User
Super User

Hi @jona4k 

This sounds like something that would be better done in DAX.  Can you please share some sample data.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.