Forum Discussion

jz7ssr's avatar
jz7ssr
Regular Visitor
7 years ago
Solved

Looping through table to create another one

Hi, I'm have a table which has been setup as follows:

 

PostCodeCompanyACompanyBCompanyCCompanyD
3015YesYesNoNo
3016NoYesNoYes
3017NoYesYesYes
3018NoNoYesYes

 

This unfortunately has company names as column headers and whether they operate or not in a particular postcode in thier own column.

 

To be able to work with it effectively, I want to transform it to the following where I loop through each row and column and add a row in the new table for each time a "Yes" is found, and then put the Company Name which is in the header and the postcode from the first column as the values.

CompanyPostCode
CompanyA3015
CompanyB3015
CompanyB3016
CompanyD3016
CompanyB3017
CompanyC3017
CompanyD3017
CompanyC3018
CompanyD3018

 

Is this possible?  I'm having trouble understanding how to use loop type functions using M Query or Dax or anything in PowerBi.

 

Thanks for any advice people can provide.

  • hi, jz7ssr

    You can use Unpovit Function in Edit Queries and then filter Value is Yes as below:

    Step1:

    Select Column CompanyA, CompanyB, CompanyC, CompanyD then click Unpovit Columns


    Step2:

    Filter the Value is "Yes"

    Result:

     

    Best Regards,

    Lin

     

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Yes, in Power Query, select your PostalCode column, right-click in select Unpivot other columns.

    • jz7ssr's avatar
      jz7ssr
      Regular Visitor

      Thankyou!  This does it all in one click, I was trying to write a complicated looping routine.

      Perfect thanks.

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

    hi, jz7ssr

    You can use Unpovit Function in Edit Queries and then filter Value is Yes as below:

    Step1:

    Select Column CompanyA, CompanyB, CompanyC, CompanyD then click Unpovit Columns


    Step2:

    Filter the Value is "Yes"

    Result:

     

    Best Regards,

    Lin