0
votes

I have a Power Query table with a column of values between 1 and 12.

I want to replace the number with a fixed set of values as shown in table below.

Period Number   Period Text
1               Jan
2               Feb
3               Mar
4               Apr
5               May
6               Jun
7               Jul
8               Aug
9               Sep
10              Oct
11              Nov
12              Dec

I have seen a solution using List.Zip that "zips" these values as below:

periodNumber = Table.Column(#"Prev Step", "Period Number"),
periodText = Table.Column(#"Prev Step", "Period Text"),
#"periodRename" = List.Zip({periodNumber, periodText}),

The List.Zip looks like this. Inside each record are two elements.

enter image description here

and then uses them to rename columns by replacing with zipped values as follows:

= Table.RenameColumns(#"Another Prev Step", #"periodRename")

What other function than Table.RenameColumns can make use of this structure? Perhaps some form of Table.ReplaceValue?

My table has a column has 1000's of rows and is in a sequence like below.

Period Number
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
1
2
etc

I want to replace all of these period numbers with their period text.

I like the idea of using List.Zip as it provides a dynamic list of periods, because sometimes the data will not have the entire 12 periods eg only 3 periods. Also the periods could also be quarters eg periodNumber = [1, 2, 3, 4] and periodText = [Q1, Q2, Q3, Q4] or years.

Is there some other way of using List.Zip to replace table values down a column instead of across table columns?

Note: The Period Numbers do not correspond to specific months. The start could be any month, for a 12 month period. So they Period Text will change. Hence need to get them dynamically.

1
Most people just merge in a date tablehorseyride

1 Answers

1
votes

Try:

monthName = Table.TransformColumns(#"Previous Step",{"Period Number", each Date.MonthName(#date(2020, _,1))})

Before Transform
enter image description here

After Transform

enter image description here

Edit: Other ways to use transform

months = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},
...
translate = Table.TransformColumns(#"Previous Table Step",{"Period Number", each months{_-1}})

to use your List.Zip
useful if the mapping is random

 translationList = List.Zip({{1,2,3,4,5,6,7,8,9,10,11,12},{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}}),
...
translate = Table.TransformColumns(typeIt,{"Period Number", each 
                    List.Range(List.Combine(translationList),
                        List.PositionOf(List.Combine(translationList),_)+1,1){0}})