Forum Discussion

kvbe's avatar
kvbe
Frequent Visitor
7 years ago
Solved

Power Query conversion from single columns to multiple columns based on rowname index

For my datamodel I need to convert a table I fetch from a database into a more easy format to work with in Power BI.

The table I receive from the database is this one. (after some cleanup and transposing it)

 

CurYrPrdStat1C
CurYrPrdStat2C
CurYrPrdStat3O
CurYrPrdStat4C
CurYrPrdStat5C
CurYrPrdStat6C
CurYrPrdStat7C
CurYrPrdStat8C
CurYrPrdStat9C
CurYrPrdStat10C
CurYrPrdStat11C
CurYrPrdStat12C
CurYrPrdStat13C
CurYrPrdStat14 
CurYrPrdStat15C
CurYrPrdEnd131/07/2018 00:00
CurYrPrdEnd231/08/2018 00:00
CurYrPrdEnd330/09/2018 00:00
CurYrPrdEnd431/10/2018 00:00
CurYrPrdEnd530/11/2018 00:00
CurYrPrdEnd631/12/2018 00:00
CurYrPrdEnd731/01/2019 00:00
CurYrPrdEnd828/02/2019 00:00
CurYrPrdEnd931/03/2019 00:00
CurYrPrdEnd1030/04/2019 00:00
CurYrPrdEnd1131/05/2019 00:00
CurYrPrdEnd1230/06/2019 00:00
CurYrPrdEnd1330/06/2019 00:00
CurYrPrdEnd14null
CurYrPrdEnd15null

 

Using power Query, I would like to achieve following format:

 

PeriodCurrentPeriodEndDateCurrentStatus
Period 131/07/2018 00:00C
Period 231/08/2018 00:00C
Period 330/09/2018 00:00O
Period 431/10/2018 00:00C
Period 530/11/2018 00:00C
Period 631/12/2018 00:00C
Period 731/01/2019 00:00C
Period 828/02/2019 00:00C
Period 931/03/2019 00:00C
Period 1030/04/2019 00:00C
Period 1131/05/2019 00:00C
Period 1230/06/2019 00:00C
Period 1330/06/2019 00:00C
Period 14null 
Period 15nullC

 

So basically what I would like to achieve is using the index number (eg. CurYrPrdEnd1) and use that one as a value. 

I tried but do not really see how I could convert this using the power query editor. 

 

After that I would like to use this table to augment my datetable I generated with the

period number added to the datetable. 

 

Something like:

 

01/07/2018 Period 1 

...

31/07/2018 Period 1

01/08/2018 Period 2 

 

etc. 

 

This using the period end date specified.

I have the date table etc and merging it with this new table I should be able to manage, just sure about the two questions regarding getting it in the right format.

2 Replies

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi,@kvbe

        After my research, you can do these follow my steps as below:

    Basic data

    Step1:

    Select column A and duplicate this column

    and then select the duplicate column replace value

    Step2:

    duplicate the table

    Step3:

    Merge basic table with duplicate table

    And then expand the table

    Step4:

    Add a conditional column

    Step5:

    filter custom column is 2

    Step6:

    Add the index column

    Step7:

    select Index column ,click Add Column->Standard->Modulo

    Step8

    filter column Modulo is 0

    Step9:

    select Column A and replace the value

    Step10:

    Remove unnecessary column and rename the column

     

    Result:

     

    here is demo, please try it.

    https://www.dropbox.com/s/ablf38rvrhravgf/Power%20Query%20conversion%20from%20single%20columns%20to%20multiple%20columns%20based%20on%20rowname%20index.pbix?dl=0

     

    Best Regards,

    Lin

     

     

     

     

    • kvbe's avatar
      kvbe
      Frequent Visitor

      Hi Lin,

       

      Thank you very much thats a neat way of approaching this! 

      Never thought about the merging + index + modulo approach. 

       

      Another type of technique I can add to my power query toolbox.