Forum

Hierarchical data o...
 
Notifications
Clear all

Hierarchical data ordering in Excel

7 Posts
3 Users
0 Reactions
91 Views
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi,

i have source table like here:

 

Screenshot_24.png

 

and the numberOfInstances like here:

 

Screenshot_25.png

 

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.png

 

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

 
Posted : 04/06/2020 12:40 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

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

 
Posted : 05/06/2020 3:00 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

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

 
Posted : 05/06/2020 10:11 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Jacek,

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

Regards

Phil

 
Posted : 05/06/2020 10:55 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

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.png

and in your resuleTable i got:

Screenshot_30.png

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

 
Posted : 06/06/2020 3:36 am
(@catalinb)
Posts: 1937
Member Admin
 

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.

 
Posted : 07/06/2020 1:23 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Catalin you are awesome!!!

Thank you very much love your solution,

It is working,
Best,
Jacek

 
Posted : 07/06/2020 6:38 am
Share: