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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Stinkin_linkin
New Member

Merging tables based on condition

Hi everyone,

I have an input table with a 0 or 1 for each category, as follows:

 

Input | Category

1 | Case1

1 | Case2

0 | Case3

0 | Case4

1 | Case5

 

There are separate tables associated with each of the 5 categories above. If the category has a 1 in the first column, then I want to merge it's table with the others. If there's a zero in front of the column, then I don't want to merge it's table with the others. If there's only zeros, then I don't want to merge any of the tables.

 

Any advice on this? I'm having trouble referencing a table that is outside of my "Merge Table" query

Thanks!

1 ACCEPTED SOLUTION

I couldn't get this method to work, but I did find another solution. First I filter out the zeros from my input table, then I converted my input table into a list, and then did a "filter by list" function in my merge query. Note: my merge query loads all the tables by default, and then filters out the tables that weren't selected by the user.

 

The code that filters by list looks like this:

= Table.SelectRows(#"Removed Columns", each (List.Contains(#"User selection",[Group]) =true ))

 

Note: Some of the labels might be confusing without seeing the whole code


Here's a youtube link to video that helped! Hopefully it's okay to post this here?

Power Query - Filtering By a List - YouTube

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Stinkin_linkin ,

 

Please try.

= Table.TransformColumns(#"Merged Queries",{"Table1", each Table.SelectRows(_,each [Input]=1)})

vcgaomsft_0-1678066242043.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

I couldn't get this method to work, but I did find another solution. First I filter out the zeros from my input table, then I converted my input table into a list, and then did a "filter by list" function in my merge query. Note: my merge query loads all the tables by default, and then filters out the tables that weren't selected by the user.

 

The code that filters by list looks like this:

= Table.SelectRows(#"Removed Columns", each (List.Contains(#"User selection",[Group]) =true ))

 

Note: Some of the labels might be confusing without seeing the whole code


Here's a youtube link to video that helped! Hopefully it's okay to post this here?

Power Query - Filtering By a List - YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors