• 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

How to add or duplicate rows based on the values of a column?|Power Query|Excel Forum|My Online Training Hub

You are here: Home / How to add or duplicate rows based on the values of a column?|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 QueryHow to add or duplicate rows based …
sp_PrintTopic sp_TopicIcon
How to add or duplicate rows based on the values of a column?
Avatar
Jim Chen
Member
Members

Power BI
Level 0
Forum Posts: 64
Member Since:
February 20, 2019
sp_UserOfflineSmall Offline
1
April 22, 2020 - 2:44 pm
sp_Permalink sp_Print

How can I add or duplicate rows when the value of a column is "Yes"? In this example, I wan to add or duplicate rows 7,8,9 based on "yes" on the Pge1.Split column.

 

Thanks!

sp_PlupAttachments Attachments
  • sp_PlupImage How-to-duplicate-rows-with-condition.PNG (223 KB)
sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4614
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
April 23, 2020 - 2:53 pm
sp_Permalink sp_Print

Hi Jim,

One way is to duplicate the query and filter the Pge1.Split column to retain rows containing 'Yes', then merge the two queries As New. Or you could add a custom column:

= if [Pge1.Split] ="Yes" then "1-2" else null)

And split the new column by delimiter and in the advanced settings choose split into 'Rows'.

Mynda

sp_AnswersTopicAnswer
Answers Post
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
3
April 23, 2020 - 4:54 pm
sp_Permalink sp_Print

Hi Mynda

Amazing,  didn't know can split into row with conditions,  there will be a lot of use case for me

Thank you !

 

Jim

Attached an sample for you

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4614
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
4
April 23, 2020 - 8:12 pm
sp_Permalink sp_Print

Glad I could help, Jim 🙂

Avatar
Jason Sibley

New Member
Members
Level 0
Forum Posts: 1
Member Since:
January 20, 2021
sp_UserOfflineSmall Offline
5
January 20, 2021 - 9:58 am
sp_Permalink sp_Print

Mynda, the second answer you gave:

Or you could add a custom column: = if [Pge1.Split] ="Yes" then "1-2" else null)

And split the new column by delimiter and in the advanced settings choose split into 'Rows'.

blew my mind!!!

Wow! Thanks so much! I registered in this forum just to tell you how grateful I am for the second solution you presented.

PS - you have fantastic YT videos. Thanks for all you do in teaching us.

Jase.

Avatar
Simon Forrest

New Member
Members
Level 0
Forum Posts: 1
Member Since:
April 24, 2021
sp_UserOfflineSmall Offline
6
April 24, 2021 - 12:44 pm
sp_Permalink sp_Print

Hi,

Agree that this was very clever and worked for me:

if [Pge1.Split] ="Yes" then "1-2" else null)Smile

 

I went a little further (pasted from advanced view):

#"Add number of rows" = Table.AddColumn(#"Filtered Rows", "Custom", each if [Frequency]="Yes" then Text.Repeat("x",BlankCount) else null),
#"Split Column by Position" = Table.ExpandListColumn(Table.TransformColumns(#"Add number of rows", {{"Custom", Splitter.SplitTextByRepeatedLengths(1), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Custom"),

 

where BlankCount is a number from a named range in the spreadsheet - this number determined the number of repeats required.  e.g. setting this as 3 creates a field value of "xxx"

Split is then by character (again creating rows) so each "x" created a new row.

 

 
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy, Norilina Harvel, QSolutions Group
Guest(s) 9
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:
Lisa Myers
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Christy Nichols
Harald Endres
Ashley Hughes
Herbie Key
Forum Stats:
Groups: 3
Forums: 24
Topics: 6528
Posts: 28594

 

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