• 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Custom column with conditions on two special values (either one of the values exists, or both values exists) in Power Query|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Custom column with conditions on two special values (either one of the values exists, or both values exists) in Power Query|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
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 QueryCustom column with conditions on tw…
sp_PrintTopic sp_TopicIcon
Custom column with conditions on two special values (either one of the values exists, or both values exists) in Power Query
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
1
August 26, 2019 - 12:41 pm
sp_Permalink sp_Print

Hi Catalin

Thank for helping in my previous post

still got one query on custom column ED

ED - If Grp 1 …… Grp X consists of User\Domain, Everyone, then return "Yes", Else "No"

See my attached 

 

Thank you so much from learning PQ from you

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
August 27, 2019 - 1:48 pm
sp_Permalink sp_Print

Use List.Contains. If you refer to a single column from a table, that is a list, you can use List functions on that column:

= Table.AddColumn(#"Added Custom2", "Custom", each if List.Contains([Grouped][User Group ID],"User\Domain users") then true else false)

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
3
August 27, 2019 - 5:01 pm
sp_Permalink sp_Print

Hi Catalin Sir,

Table.AddColumn("[Count]", "ED", each if List.Contains([Count][User Group ID], "Everyone") then true else false

Got error,  my syntax correct?

and how to incorporate the OR,  that is the following conditions fulfilled

"Everyone"

"User\Domain users"

"Everyone" and "User\Domain users"

 

Thank You

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
August 27, 2019 - 5:18 pm
sp_Permalink sp_Print

Hi Chris,

When you click the button to add new column, in the dialog window that shows up you should paste only the formula, not the entire step syntax. The entire step syntax can be used only if you edit the M code. The formula for adding this new column should be:

=if List.Contains([Count][User Group ID], "Everyone") then true else false

See the List functions description, there is a List.Contains function, List.ContainsAny, List.ContainsAll.

List.ContainsAny can be used in an OR scenario, List.ContainsAll can be used in a AND scenario.

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
5
August 28, 2019 - 12:56 pm
sp_Permalink sp_Print

Hi Catalin,

my current ED 

Table.AddColumn(#"Added Custom2", "ED", each if List.ContainsAny([Grouped][User Group ID], {"Everyone","User\Domain users"}) then "Yes" else "No")

123,  345 and 998 should be "No"

 

realised that only equal to "Yes" if

"Everyone","User\Domain users" and all the rest null is equal

"User\Domain users" and all the rest null is equal

"Everyone" and all the rest null is equal

 

to "Yes"

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
6
August 28, 2019 - 12:56 pm
sp_Permalink sp_Print

Catalin,

Need your expertise to advise on the code to take care null

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
7
August 28, 2019 - 1:23 pm
sp_Permalink sp_Print

Chris Yap said
and how to incorporate the OR,  that is the following conditions fulfilled
"Everyone"
"User\Domain users"
"Everyone" and "User\Domain users"
 
  

I think the query returns what you described above, not sure I understand what you mean.

From those User ID's, which one should return No and which should return Yes?

123
345
678
898
998
1190
1298
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
8
August 28, 2019 - 1:40 pm
sp_Permalink sp_Print

Hi Catalin,

123,  345 and 998 should return "No",  basically only

"Everyone" + the rest null
"User\Domain users"  + the rest null
"Everyone" and "User\Domain users"  + the rest null

return "Yes"

 

How to code it in the ListContainAll or ListcontainAny ?

 

Thank you !

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
9
August 28, 2019 - 1:50 pm
sp_Permalink sp_Print

Ok, I understand that 998 should return no, but why 898 should return yes?

Add a new column with this formula:

if List.Count([Grouped][User Group ID]) = List.Count(List.Select([Grouped][User Group ID], each List.Contains({"Everyone","User\Domain users"}, _))) then "Yes" else "No"

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
10
August 28, 2019 - 2:02 pm
sp_Permalink sp_Print

898 is return No

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
11
August 28, 2019 - 2:08 pm
sp_Permalink sp_Print

Catalin,   thank you so much on your expertise in PQ,   really appreciate it 

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
12
August 28, 2019 - 2:20 pm
sp_Permalink sp_Print

Catalin

are you able to explain your formula as layman as possible

Thank you very much

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
13
August 28, 2019 - 2:44 pm
sp_Permalink sp_Print

Chris Yap said
123,  345 and 998 should return "No",  basically only

Chris Yap said
898 is return No  

898 returns no, but it was not in the list you mentioned that should return no.

1. Left side of the equation: formula:  List.Count([Grouped][User Group ID]) will return a number that represents how many values are in the User Group ID column (excludes null values from that column).

2. Right side of the equation: formula: List.Select([Grouped][User Group ID], each List.Contains({"Everyone","User\Domain users"}, _)) will return another list with only those entries from [User Group ID] that can be found in this list: {"Everyone","User\Domain users"}, obviously there can be between 0 or 2 items in this list produced, if there is no match or one or both values are found.

If you count the items from the list produced with this last formula, you will be able to compare it with the full list count. If the count is the same, then your conditions are met.

if List.Count([Grouped][User Group ID]) = List.Count(List.Select([Grouped][User Group ID], each List.Contains({"Everyone","User\Domain users"}, _))) then "Yes" else "No"

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
14
August 28, 2019 - 4:24 pm
sp_Permalink sp_Print

Hi Catalin,

I get what you mean,   898 got no "Everyone","User\Domain user" at all,  this is not true in real environment,  I didn't mock the data accurately  haha

 

Thank you !

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Richard West, Wesley Burchnall, Clayton Watson
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 204
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Bhuwan Devkota
Kathryn Patton
Maria Conatser
Jefferson Granemann
Glen Coulthard
Nikki Fox
Rachele Dickie
Forum Stats:
Groups: 3
Forums: 24
Topics: 6222
Posts: 27291

 

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

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • 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
 

Company

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

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.