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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SEDE
Employee
Employee

UNION two tables and fill empty rows

Hey all...hopefully an easy one for all of you smart people here!

 

A quick illistrative example is below, with an explanation below that. Note that the Unique ID is simply used to tie answers together, so no extra thought needed for this piece:

 

SEDE_6-1624315938003.png

 

I'm trying to combine two tables, where the two columns in table one will apphend to the end of one of the columns of table two to form a new third table. Then I need the column header for those values in table one to fill the rows adjacent. I've managed to get really close, but I can't figure out how to pass a value as anything other than a blank. Here's what I have:

 

Combo = 
VAR tableone =
    SELECTCOLUMNS ( UniqueID, "ID", [UniqueID], "Answer", [Answer ABC], "Question", BLANK() )
VAR tableoneagain =
    SELECTCOLUMNS ( UniqueID, "ID", [UniqueID], "Answer", [Answer #], "Question", BLANK() )
VAR tabletwo =
    SELECTCOLUMNS ( UniqueID, "ID", [UniqueID], "Answer", [Answer], "Question", [Question] )
RETURN
    UNION ( tableone, tableoneagain, tabletwo )

 

Basically I need the "Blank ()" to instead be "Answer ABC" for the first SELECTCOLUMNS and "Answer #" for the second. Right now with the code above, I'm getting this:

 

SEDE_4-1624315687929.png

 

Thanks!!!

 

1 ACCEPTED SOLUTION

Hi @SEDE ,

 

You can try to unpivot columns and then append the query in the Power Query Editor, like this:

 

image.png

image.pngimage.pngimage.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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
amitchandak
Super User
Super User

@SEDE , based on what I got, You can add a blank in place Answer ABC, just need to make sure that is not the first table

 

Combo =
VAR tableone =
SELECTCOLUMNS ( UniqueID, "ID", [UniqueID], "Answer", blank(), "Question", BLANK() )
VAR tableoneagain =
SELECTCOLUMNS ( UniqueID, "ID", [UniqueID], "Answer", [Answer #], "Question", BLANK() )
VAR tabletwo =
SELECTCOLUMNS ( UniqueID, "ID", [UniqueID], "Answer", [Answer], "Question", [Question] )
RETURN
UNION (  tabletwo,tableoneagain,tableone )

Hey amitchandak! I appreciate the attempt. I'm actually trying to get rid of all the blanks, and replace them with the column header from each particular column. This is what I'm hoping to achieve:

 

SEDE_0-1624459366991.png

 

Thanks!

 

Hi @SEDE ,

 

You can try to unpivot columns and then append the query in the Power Query Editor, like this:

 

image.png

image.pngimage.pngimage.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

After finagling some table names and stuff, this works great! Thank you so much!

 

-SEDE

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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