Forum Discussion
Duplicate a single value and add a criteria
Hi,
I would like to duplicate every single value, and to effect for each one the actual year and the previous like the example below.
It is possible to do this in power query ?
Here the data example
| DATA | VALUE |
| A | 40 |
| B | 20 |
| C | 10 |
Thanks
- Anonymous5 years ago
You can make a list column and expand it. First, I would make a new query named Years, which will be your list of years:
Yr = Date.Year(DateTime.LocalNow()),
Yrs = {Yr, Yr-1, Yr-2}
Now you should have a list of 2021, 2020, and 2019. Now go back to your main query, and add a step:
Last3Yrs = Table.AddColumn(LastStepName, "Years", each Years)
Then you can expand the list column and choose "Expand to new rows".
That's it!
--Nate
1 Reply
- AnonymousNot applicable
You can make a list column and expand it. First, I would make a new query named Years, which will be your list of years:
Yr = Date.Year(DateTime.LocalNow()),
Yrs = {Yr, Yr-1, Yr-2}
Now you should have a list of 2021, 2020, and 2019. Now go back to your main query, and add a step:
Last3Yrs = Table.AddColumn(LastStepName, "Years", each Years)
Then you can expand the list column and choose "Expand to new rows".
That's it!
--Nate