• 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

Need to create a custom column for New customer using group by and IF ELSE statement.|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Need to create a custom column for New customer using group by and IF ELSE statement.|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 QueryNeed to create a custom column for …
sp_PrintTopic sp_TopicIcon
Need to create a custom column for New customer using group by and IF ELSE statement.
Avatar
Vaishnavi Manjunath

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
February 17, 2022
sp_UserOfflineSmall Offline
1
February 17, 2022 - 5:41 am
sp_Permalink sp_Print sp_EditHistory

Hi All,

I am brand new member of this forum and also an apprentice in PQ- M language.

I need help to build two custom columns :
1) Sku Count
2) New Customer Flag

Please see the attached sample file fo reference. Until I learnt about PQ, I have been deriving the above two using Excel Countifs formulas.

There is a reference date  which is a constant for this year, but may change next year.

I tried the below for deriving SKU Count but got the below error:

= Table.Group(Source,"Account-Zip-Sku",{{"Sku Count", each if [Invoice Dates] <= [Start of Month] then "0" else "1"}})

Expression.Error: We cannot apply operator <= to types List and List.
Details:
Operator=<=
Left=[List]
Right=[List]

If you have a much stable query I can learn or depend on to achieve the two outcomes please share.

Thank you!

Avatar
Vaishnavi Manjunath

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
February 17, 2022
sp_UserOfflineSmall Offline
2
February 17, 2022 - 8:53 am
sp_Permalink sp_Print sp_EditHistory

Continuing some more details on my original post.
While my post was getting verified, I did some research and performed these two queries to achieve the two custom columns I have mentioned above.

Steps I followed

  1. Uploaded data into Power Query
  2. I referenced my orginal PQTest query which I loaded to PQ.
  3. then wrote the below in advanced editor:
    let
    Source = PQTest,
    Custom1 = Table.Group(RawData_iDigSales,"Account-Zip-Sku",{{"Sku Count", each if [Invoice Dates] = [Start of Month] then "0" else "1"}})
    in
    Custom1

From the above Helper Query I derived  a partial or incorrect Sku Count.

This is where I hit the road block : I wanted to use the query 

let
Source = PQTest,
Custom1 = Table.Group(RawData_iDigSales,"Account-Zip-Sku",{{"Sku Count", each if [Invoice Dates] <= [Start of Month] then "0" else "1"}})
in
Custom1

But PQ threw an error as below when I include "<=" expression in the query.

Expression.Error: We cannot apply operator <= to types List and List.
Details:
Operator=<=
Left=[List]
Right=[List]
The above is Problem number 1
Yet I continued becuase I am hoping to find the solution to problem number 1.

      4. Then I merged the above helper query with the PQ Test query as a new table called it Merge 1

      5. Using the Merge 1, I referenced the query to derive the next custom column ="New Account"

      6. Used the below query in advanced editor:

let
_reference_date = #date(2021,01,01),
Source = Merge1,
// #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sku Count", Int64.Type}})
Custom1 = Table.Group(Source,"Account-Zip-Sku",{{"New Account",each if List.Min([Sku Count]) = 0 and List.Min([Invoice Date]) >= _reference_date then "Y" else"N"}})
in
Custom1

  

Now my request to all is, is there a way to fix the "<=" expression error and is there a more agile way to derive these custom columns instead of the long process I have here?

Note: Although I am grouping, I still need to retain all rows from the orginal table.

Thank you for reading and your help.

Avatar
Vaishnavi Manjunath

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
February 17, 2022
sp_UserOfflineSmall Offline
3
February 17, 2022 - 9:11 am
sp_Permalink sp_Print

Please see the attahed for the new sample data and the test queries I have performed.

 

https://docs.google.com/spread.....38;sd=true

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
4
February 17, 2022 - 12:18 pm
sp_Permalink sp_Print

Hi,

Can attach your PQ here for us to take a look on your error.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Alan Sidman, QSolutions Group
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
Hans Hallebeek: 185
Newest Members:
Kate Dyka
Kwaje Alfred Mogga
thong nguyen
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Doug Milne
Siobhan Stringer
Forum Stats:
Groups: 3
Forums: 24
Topics: 6547
Posts: 28656

 

Member Stats:
Guest Posters: 49
Members: 32832
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.