Forum

How to create array...
 
Notifications
Clear all

How to create array of numbers from 1 row?

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

Hi Guys,

i have table like here:

Topology|Tier|TotalServers

Topology1 Tier1 4
Topology1 Tier2 2
Topology2 Tier3 3

as you can see there is TotalServers for each topology and tier. 

And now the expected result is:

Topology|TierServer|Number

Topology1 Tier1 1
Topology1 Tier1 2
Topology1 Tier1 3
Topology1 Tier1 4
Topology1 Tier2 1
Topology1 Tier2 2
Topology2 Tier3 1
Topology2 Tier3 2
Topology2 Tier3 3

 

so generally i want to break TotalServers into Servernumber when TotalServers is max and min =1. Something like list.generate from 1 to n where n is the TotalServers. 

Can anybody help?
Best,
Jacek

 
Posted : 27/07/2021 6:09 am
Anders Sehlstedt
(@sehlsan)
Posts: 968
Prominent Member
 

Hello,

A similar question was asked in this post, for me the suggested approach works just fine, check if it works for you.

 
Posted : 27/07/2021 6:14 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi,

thank you.

Hmm i stucked a little. 

I tried example from link above and i finished with:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Building", type text}, {"Device", type text}, {"Ports", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Repeat("z",[Ports])),
#"Split Column by Position" = Table.ExpandListColumn(Table.TransformColumns(#"Added Custom", {{"Custom", Splitter.SplitTextByRepeatedLengths(1), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Custom"),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Custom", type text}})
in
#"Changed Type1"

Screenshot_188.png

What i am missing?

Best,
Jacek

 
Posted : 28/07/2021 4:51 am
(@debaser)
Posts: 836
Member Moderator
 

You could use something like this I think:

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Building", type text}, {"Device", type text}, {"Ports", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Counter", each {1..[Ports]}),
#"Expanded Counter" = Table.ExpandListColumn(#"Added Custom", "Counter")
in
#"Expanded Counter"

 
Posted : 28/07/2021 6:35 am
Anders Sehlstedt
(@sehlsan)
Posts: 968
Prominent Member
 

Hello,

Velouria's code gives a better result. But to answer your question, you got the expected result for that text split code, so nothing missed on your part. You got a new row for each z in the custom column, it is however not counting as what Velouria's code does.

 
Posted : 28/07/2021 7:37 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi,

 

thank you very much.

It is working. 
Ok so the link above is not doing the right solution? 

One question:

{1..[Ports]} what these ".." means within list? 
Best,
Jacek

 
Posted : 28/07/2021 8:57 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

hi Jaryszek,

The .. in {1..[Ports]} means include all numbers from 1 to [Ports]

Further reading Power Query Lists • My Online Training Hub

regards

Phil

 
Posted : 28/07/2021 7:17 pm
Share: