Forum Discussion

Juju-PowerBI's avatar
Juju-PowerBI
Frequent Visitor
5 years ago
Solved

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

 

DATAVALUE
A40
B20
C10

 

Thanks

  • Anonymous's avatar
    Anonymous
    5 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

  • Anonymous's avatar
    Anonymous
    Not 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