0

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
  • 1
    Most people just merge in a date table Commented Jul 26, 2021 at 15:57

1 Answer 1

1

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}})

Sign up to request clarification or add additional context in comments.

6 Comments

I should add this to my question. 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.
@curtisp You can still use the column transform method. You would just map the number to whatever month it represented. How to do that would depend on the relationship between the number and the month. The most complicated situation would be if the relationship was random. But if it's sequential, it would be pretty simple, using that technique.
The relationship btwn Period Numbers and Period Text is in the List.Zip. So I am looking for way to access it to fill down instead of across columns. It will be dynamic. The List.Zip record count will be dynamic as will the text values.
@curtisp I have edited my question to demonstrate some other ways of getting your desired results. Including using your List.Zip which would be handy if the mapping was random.
@curtisp Glad it works for you. I would suggest that you set the list up as List.Combine(List.Zip({...}) instead of executing List.Combine multiple times in the transform operation. Note that returnValue is always indexed at lookupValue {lookupValue postion+1}. You could even buffer it if speed is an issue.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.