• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Unique low value in group|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Unique low value in group|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryUnique low value in group
sp_PrintTopic sp_TopicIcon
Unique low value in group
Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
1
October 21, 2019 - 9:53 am
sp_Permalink sp_Print

I have 20 golfers, each playing 18 holes. I can't seem to figure out the formula, in power query, that I need to find the single minimum score (no duplicates) per each hole. Any help would be greatly appreciated.

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
October 21, 2019 - 1:34 pm
sp_Permalink sp_Print

Sounds like a "Group By" transformation to me. If you group by hole (and player probably, not sure) and choose a Count as aggregation, you will be able to remove those with more than 1 record (duplicates).

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
3
October 24, 2019 - 10:40 am
sp_Permalink sp_Print

I don't want to delete or change anything. I want to know the unique (single value) low score on that hole. I am new to power query and haven't been able to figure this out.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
October 24, 2019 - 12:50 pm
sp_Permalink sp_Print

Can you upload a sample file so we can see what's in there?

I don't play golf ...  My knowledge on this is full of holes. 😉

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
5
October 25, 2019 - 9:16 am
sp_Permalink sp_Print

If you bring up the queries and open tblDay1 you will see the query. Each player has 18 scores, one score on each of the 18 holes. The end result is to find the single lowest unique (no duplicates) score value of all the players on each of the holes. The maximum number of results is 18 - 1 value per hole.  Any other questions, feel free to ask.  Thanks for your involvement.  Here's a link to the file;

https://www.dropbox.com/s/mejh......xlsm?dl=0

Sal

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
6
October 25, 2019 - 9:37 am
sp_Permalink sp_Print

Here is a picture of the query:

 

tblDay1Query-Copy-1.PNGImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage tblDay1Query-Copy.PNG (146 KB)
  • sp_PlupImage tblDay1Query-Copy-1.PNG (146 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
7
October 25, 2019 - 1:21 pm
sp_Permalink sp_Print

Hi Sal,

I added 4 steps to your query, please check if this is what you need:

let
Source = Excel.CurrentWorkbook(){[Name="tblDay1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Player", type text}, {"Sex", type text}, {"SCGA", type number}, {"Hcp", Int64.Type}, {"1", Int64.Type}, {"2", Int64.Type}, {"3", Int64.Type}, {"4", Int64.Type}, {"5", Int64.Type}, {"6", Int64.Type}, {"7", Int64.Type}, {"8", Int64.Type}, {"9", Int64.Type}, {"F9", Int64.Type}, {"F Net", Int64.Type}, {"10", Int64.Type}, {"11", Int64.Type}, {"12", Int64.Type}, {"13", Int64.Type}, {"14", Int64.Type}, {"15", Int64.Type}, {"16", Int64.Type}, {"17", Int64.Type}, {"18", Int64.Type}, {"B9", Int64.Type}, {"B Net", Int64.Type}, {"Gross", Int64.Type}, {"Net", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Player", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"SCGA"}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Player", "Sex", "Hcp", "B9", "B Net", "Gross", "Net"}, "Attribute", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Attribute] <> "F Net" and [Attribute] <> "F9"),
#"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Attribute", "Hole #"}, {"Value", "Score"}}),
#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Player", "Sex", "Hcp", "Score", "Hole #", "B9", "B Net", "Gross", "Net"}),
#"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"B9", "B Net", "Gross", "Net"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns1",{{"Hole #", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", { "Hole #"}, {{"Min", each List.Min([Score]), type number}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Hole #"}, #"Grouped Rows", {"Hole #"}, "Grouped Rows", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "Min Value for current Hole", each if [Grouped Rows][Min]{0}=[Score] then [Score] else null),
#"Removed Columns2" = Table.RemoveColumns(#"Added Custom",{"Grouped Rows"})
in
#"Removed Columns2"

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
8
October 26, 2019 - 9:39 am
sp_Permalink sp_Print

Hi Catalin,

Not bad for being full of holes.  Almost, I need the min to be the lowest non-duplicated value. In english, the single lowest score.  The answer per hole will be one unique score or none.

When I was trying to figure this out, I thought I saw a min function, in M, that gave a single unique value and minN function for the number of min values found. Did I misunderstand?

Sal

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
9
October 26, 2019 - 12:25 pm
sp_Permalink sp_Print

Hi Sal,

Have you tried the query provided?

I continued your query with this step:

#"Grouped Rows" = Table.Group(#"Changed Type1", { "Hole #"}, {{"Min", each List.Min([Score]), type number}}),

This step returns a list of 18 holes with the minimum score for them, no matter which player achieved that score.

I can see no duplicates here, so I don't understand your point.

After this step, I added a #"Merged Queries" step with the following logic:

While each hole has a single minimum score, there can be more than one layer that may have achieved that minimum score.

Therefore, the last step that creates the column "Min Value for current Hole" will identify all the players that achieved the minimum score for each hole. If you filter out the null values in this column, you may see one ore more players with the minimum score for that hole.

 

If there is something else you need, please provide a manual example of how the final result should look like, it's much easier than learning the entire game.

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
10
October 27, 2019 - 9:22 am
sp_Permalink sp_Print

Hi Catalin,

Yes I tried the query and found several players on a hole that had the same min value. That's why I said "almost" in my reply.  Anyway, The file I attached shows the result that is wanted. I did this in VBA, now attempting the upgrade.

Sal

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
11
October 27, 2019 - 2:17 pm
sp_Permalink sp_Print

If more than 1 player have the same minimum score, which one should be removed from the list? Based on what criteria or calculation?

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
12
October 28, 2019 - 6:21 am
sp_Permalink sp_Print

Hello Catalin,

Nothing nor anybody to be removed. Referring back to the example, just below the net scores are the "Skins". A skin is either a birdie or a low net score. I have done birdies, now trying to do low nets to arrive at the skins. The skins are shown by player and denote the type and shows each players total number of skins and the total for the round. Hope this helps.

Sal

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
13
October 28, 2019 - 3:28 pm
sp_Permalink sp_Print

Doesn't help, just brings more confusion. Remember, I know nothing about this game and its rules.

You mentioned that " I have done birdies, now trying to do low nets to arrive at the skins.", but I have no idea what a "bird" or an "eagle" or even "nets" means in this game.

Based on the query structure you provided, what do you expect to get? Below is an extract of results, showing the min Score for current hole.

Player Sex Hcp Score Hole # Min Value for current Hole
Bauman, Dick M 33 6 1 null
Bauman, Dick M 33 7 2 null
Bauman, Dick M 33 8 3 null
Bauman, Dick M 33 4 4 null
Bauman, Dick M 33 5 5 null
Bauman, Dick M 33 4 6 null
Bauman, Dick M 33 6 7 null
Bauman, Dick M 33 5 8 null
Bauman, Dick M 33 4 9 null
Bauman, Dick M 33 7 10 null
Bauman, Dick M 33 4 11 null
Bauman, Dick M 33 5 12 null
Bauman, Dick M 33 6 13 null
Bauman, Dick M 33 5 14 null
Bauman, Dick M 33 4 15 null
Bauman, Dick M 33 5 16 null
Bauman, Dick M 33 4 17 4
Bauman, Dick M 33 8 18 null
Bauman, Maria F 36 6 1 null
Bauman, Maria F 36 9 2 null
Bauman, Maria F 36 5 3 null
Bauman, Maria F 36 4 4 null
Bauman, Maria F 36 6 5 null
Bauman, Maria F 36 7 6 null
Bauman, Maria F 36 5 7 null
Bauman, Maria F 36 7 8 null
Bauman, Maria F 36 3 9 3
Bauman, Maria F 36 6 10 null
Bauman, Maria F 36 4 11 null
Bauman, Maria F 36 7 12 null
Bauman, Maria F 36 7 13 null
Bauman, Maria F 36 7 14 null
Bauman, Maria F 36 5 15 null
Bauman, Maria F 36 6 16 null
Bauman, Maria F 36 7 17 null
Bauman, Maria F 36 8 18 null
Brown, Mark M 11 6 1 null
Brown, Mark M 11 6 2 null
Brown, Mark M 11 4 3 4
Brown, Mark M 11 3 4 3
Brown, Mark M 11 5 5 null
Brown, Mark M 11 5 6 null
Brown, Mark M 11 5 7 null
Brown, Mark M 11 6 8 null
Brown, Mark M 11 4 9 null
Brown, Mark M 11 6 10 null
Brown, Mark M 11 4 11 null
Brown, Mark M 11 7 12 null
Brown, Mark M 11 6 13 null
Brown, Mark M 11 4 14 4
Brown, Mark M 11 4 15 null
Brown, Mark M 11 7 16 null
Brown, Mark M 11 5 17 null
Brown, Mark M 11 7 18 null
Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
14
October 29, 2019 - 9:56 am
sp_Permalink sp_Print

Hi Catalin,

Sorry for all the confusion. Let me start fresh. Looking at the net scores section. Lets say that it shows that I have 11 Salesman and 18 days of sales. For whatever reason I want to find the worst single   salesman on each day. This is shown as the red numbers.

In the power query, we have players and score per hole. I want to find the lowest single player score on each hole.

You questioned birdie, low net and skins - names are not important to our task. I did the birdies in another query that I will merge with this one, when it is completed, and get the "skins".

I have  attached a Pivot table of the query and red bold the wanted results .Pivot-Table-Example.PNGImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage Pivot-Table-Example.PNG (154 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
15
October 29, 2019 - 2:30 pm
sp_Permalink sp_Print sp_EditHistory

Add a new column with this formula (formula is in red):

 = Table.AddColumn(#"Added Custom", "Is Single Min", (rw)=> Table.RowCount(Table.SelectRows(#"Added Custom", each [Min Value for current Hole]<>null and [#"Hole #"]=rw[#"Hole #"]))=1 and rw[Min Value for current Hole]<>null, type logical)

This column returns TRUE for those 4 values in red from your example.

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
16
November 8, 2019 - 12:04 pm
sp_Permalink sp_Print

Hello again Catalin,

Thank you for the formula. As I said before, I am new to structured formulas, and was wondering if you could explain the formula in English. Also in verifying the example did your query include the min column also?  Thanks, Sal

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
17
November 8, 2019 - 2:03 pm
sp_Permalink sp_Print

Here is the full query then:

let
Source = Excel.CurrentWorkbook(){[Name="tblDay1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Player", type text}, {"Sex", type text}, {"SCGA", type number}, {"Hcp", Int64.Type}, {"1", Int64.Type}, {"2", Int64.Type}, {"3", Int64.Type}, {"4", Int64.Type}, {"5", Int64.Type}, {"6", Int64.Type}, {"7", Int64.Type}, {"8", Int64.Type}, {"9", Int64.Type}, {"F9", Int64.Type}, {"F Net", Int64.Type}, {"10", Int64.Type}, {"11", Int64.Type}, {"12", Int64.Type}, {"13", Int64.Type}, {"14", Int64.Type}, {"15", Int64.Type}, {"16", Int64.Type}, {"17", Int64.Type}, {"18", Int64.Type}, {"B9", Int64.Type}, {"B Net", Int64.Type}, {"Gross", Int64.Type}, {"Net", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Player", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"SCGA"}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Player", "Sex", "Hcp", "B9", "B Net", "Gross", "Net"}, "Attribute", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Attribute] <> "F Net" and [Attribute] <> "F9"),
#"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Attribute", "Hole #"}, {"Value", "Score"}}),
#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Player", "Sex", "Hcp", "Score", "Hole #", "B9", "B Net", "Gross", "Net"}),
#"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"B9", "B Net", "Gross", "Net"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns1",{{"Hole #", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", { "Hole #"}, {{"Min", each List.Min([Score]), type number}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Hole #"}, #"Grouped Rows", {"Hole #"}, "Grouped Rows", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "Min Value for current Hole", each if [Grouped Rows][Min]{0}=[Score] then [Score] else null),
#"Removed Columns2" = Table.RemoveColumns(#"Added Custom",{"Grouped Rows"}),
#"Added Custom1" = Table.AddColumn(#"Removed Columns2", "Is Single Min", (rw)=> Table.RowCount(Table.SelectRows(#"Added Custom", each [Min Value for current Hole]<>null and [#"Hole #"]=rw[#"Hole #"]))=1 and rw[Min Value for current Hole]<>null,type logical)
in
#"Added Custom1"

The formula takes into account the previous column added "Min Value for current Hole". You can see it in the formula if you take a closer look.

What the formula does:

Count the rows from entire table (from previous step) where "Min Value for current Hole" is not empty for the current hole. If this count is =1 and current row "Min Value" is not null, it will return TRUE.

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
18
November 9, 2019 - 10:07 am
sp_Permalink sp_Print

Hello Catalin,

Can you tell me what rw means in the formula.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
19
November 9, 2019 - 2:25 pm
sp_Permalink sp_Print

rw refers to current row context.

Table.AddColumn(#"Removed Columns2", "Is Single Min", (rw)=> Table.RowCount(

is equal to:

Table.AddColumn(#"Removed Columns2", "Is Single Min", each Table.RowCount(

Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
20
November 10, 2019 - 1:26 am
sp_Permalink sp_Print

Catalin - you've been great, thanks for your patience and all your assistance.  Sal

sp_AnswersTopicAnswer
Answers Post
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Susan VanRiper, Sue Hammond, Tracy English, David Panthol, Mohamed Touahria
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
David von Kleek
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Christy Nichols
Harald Endres
Ashley Hughes
Herbie Key
Trevor Pindling
Forum Stats:
Groups: 3
Forums: 24
Topics: 6528
Posts: 28594

 

Member Stats:
Guest Posters: 49
Members: 32817
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.