• 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

Hierarchical data ordering in Excel|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Hierarchical data ordering in Excel|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 QueryHierarchical data ordering in Excel
sp_PrintTopic sp_TopicIcon
Hierarchical data ordering in Excel
Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
1
June 4, 2020 - 2:40 am
sp_Permalink sp_Print sp_EditHistory

Hi,

i have source table like here:

 

Screenshot_24.pngImage Enlarger

 

and the numberOfInstances like here:

 

Screenshot_25.pngImage Enlarger

 

The number of instance can be from 1 to n, for example we have only 2. So resultTable should be changed accordingly.

The last table result table is looking like:

 

Screenshot_26.pngImage Enlarger

 

So as you can see there is Instance number for each TopologyTier in order way. 

We have just doubled rows because we have instanceNumber from 1 to 2. 
How can i build the Result table using PQ? 

Cany anybody help?
Please,
Jacek

sp_PlupAttachments Attachments
  • sp_PlupImage Screenshot_24.png (80 KB)
  • sp_PlupImage Screenshot_25.png (56 KB)
  • sp_PlupImage Screenshot_26.png (85 KB)
sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
June 4, 2020 - 5:00 pm
sp_Permalink sp_Print

Hi Jacek,

I'm not clear on what result you actually want.  Is the result table in your image what you want?  Or is this what you end up with when trying to create the desired result in PQ?

Regards

Phil

Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
3
June 5, 2020 - 12:11 am
sp_Permalink sp_Print sp_EditHistory

hi Phil!

thank you! 
Exactly, i want to have Result table using PQ but i am having issues how can i merge Sourcetable and NumbeOfInstace table together to have repeating rows based on MaxInstance column...

Best,
Jacek

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
June 5, 2020 - 12:55 pm
sp_Permalink sp_Print

Hi Jacek,

The final table is on a new sheet 'Final Query'.

Regards

Phil

Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
5
June 5, 2020 - 5:36 pm
sp_Permalink sp_Print

Hi Phil,

thank you very much. This is not working unfortunately. 

I changed maxInstance from 2 to 3 and now i should get:

Screenshot_29.pngImage Enlarger

and in your resuleTable i got:

Screenshot_30.pngImage Enlarger

so as you can see this is not copying and increasing automatically rows...
If i will add 4 as MaxInstance i will have rows from 1 to 4 times 3 and so on...

Can you please help?
Jacek

sp_PlupAttachments Attachments
  • sp_PlupImage Screenshot_29.png (430 KB)
  • sp_PlupImage Screenshot_30.png (292 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
June 6, 2020 - 3:23 pm
sp_Permalink sp_Print sp_EditHistory

Basically, you want to repeat all rows from Source table, based on MaxInstance count?

Try this query for t_SourceTable:

let
Source = Excel.CurrentWorkbook(){[Name="t_SourceTable"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Environment", type text}, {"Infrastructure", type text}, {"Region", type text}, {"Topology", type text}, {"Tier", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Topology", "Tier"}, t_Instances, {"Topology", "Tier"}, "t_Instances", JoinKind.LeftOuter),
#"Expanded t_Instances" = Table.ExpandTableColumn(#"Merged Queries", "t_Instances", {"MinInstance", "MaxInstance"}, {"MinInstance", "MaxInstance"}),
#"Added Custom" = Table.AddColumn(#"Expanded t_Instances", "Custom", each {[MinInstance]..[MaxInstance]}),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
#"Expanded Custom"

The key here is to create a list, based on your conditions: {[MinInstance]..[MaxInstance]}. Then just expand the list into rows, this will create duplicate rows for each item in list.

Load results to sheet, hope this is what you're after.

sp_AnswersTopicAnswer
Answers Post
Avatar
jaryszek
Member
Members
Level 0
Forum Posts: 183
Member Since:
February 1, 2019
sp_UserOfflineSmall Offline
7
June 6, 2020 - 8:38 pm
sp_Permalink sp_Print

Catalin you are awesome!!!

Thank you very much love your solution,

It is working,
Best,
Jacek

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Roslyn Finlayson, Shanna Henseler
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6210
Posts: 27236

 

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