Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jz7ssr
Regular Visitor

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.

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
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


6.PNG

7.PNG

Step2:

Filter the Value is "Yes"

9.PNG

Result:

8.PNG

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
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


6.PNG

7.PNG

Step2:

Filter the Value is "Yes"

9.PNG

Result:

8.PNG

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
avknishokpbi
Frequent Visitor

Hi,

 

You un-pivot in the edit query window.

 

Go to the section "Unpivot; Turning Columns to Rows; Name, Values" in below link you will find the step by step process

 

http://radacad.com/pivot-and-unpivot-with-power-bi

 

 

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

Perfect thanks.

Greg_Deckler
Community Champion
Community Champion

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



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors