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
AgoZ_KH
Resolver I
Resolver I

How to UNION more columns in a single column with Power Query

I had set a DAX formula like this:

Problems = UNION
(
SELECTCOLUMNS(TABX,"problems",TABX[Pbl_1]),
SELECTCOLUMNS(TABX,"problems",TABX[Pbl_2]),
SELECTCOLUMNS(TABX,"problems",TABX[Pbl_3]),
SELECTCOLUMNS(TABX,"problems",TABX[Pbl_4]),
SELECTCOLUMNS(TABX,"problems",TABX[Pbl_5]),
SELECTCOLUMNS(TABX,"problems",TABX[null])
)

The risult is a new table with a single column like:

Problems

----------

Pbl_1
Pbl_1
Pbl_1
Pbl_1
Pbl_2
Pbl_2
Pbl_2
Pbl_3
Pbl_3
Pbl_4
Pbl_4
Pbl_4
Pbl_4
Pbl_4
Pbl_5
Pbl_5
null
null
null

 

I want obtain the same result in power query, but as now if I use Query merge (with an empty table) the result table is:

| Pbl | Pbl_1 | Pbl_2 || Pbl_3 || Pbl_4 || Pbl_5 |

 null   Pbl_1   Pbl_2     null     Pbl_4    Pbl_5
 null   null      Pbl_2    Pbl_3   Pbl_4    null
 null   null      null       Pbl_3   Pbl_4    null
 null   Pbl_1   Pbl_2     null     null      Pbl_5
 null   Pbl_1   null        Pbl_3  null      Pbl_5

 

And if i use Append Query the result table is:

 

 Pbl_1|Pbl_2 ||Pbl_3 ||Pbl_4 | Pbl_5 |
     
Pbl_1nullnullnullnull
nullnullnullnullnull
nullnullnullnullnull
Pbl_1nullnullnullnull
Pbl_1nullnullnullnull
     
nullPbl_2nullnullnull
nullPbl_2nullnullnull
nullnullnullnullnull
nullPbl_2nullnullnull
nullnullnullnullnull
     
nullnullnullnullnull
nullnullPbl_3nullnull
nullnullPbl_3nullnull
nullnullnullnullnull
nullnullPbl_3nullnull
     
nullnullnullPbl_4null
nullnullnullPbl_4null
nullnullnullPbl_4null
nullnullnullnullnull
nullnullnullnullnull
     
nullnullnullnullPbl_5
nullnullnullnullnull
nullnullnullnullnull
nullnullnullnullPbl_5
nullnullnullnullPbl_5

 

What I make wrong?

Can anyone show me how to achieve the same result as the DAX formula in Power Query??

Thanks so much!

AgoZ

2 REPLIES 2
HotChilli
Super User
Super User

You'll get a better answer if you post some sample data, then show what the desired result is.

--

I'm a little confused but I 'think' you want to Unpivot the columns from your original table (select all columns from the headers, right-click on the header and the option is there)

Hi @HotChilli !

thanks for replay!

 

I'd more semplified my needs and the example. The unpivot function is not useful in my case. 

Here a graphical example. I have a table like this:

A

B

C

D

E

PB1

 

PB3

PB4

PB5

PB1

PB2

 

PB4

 
 

PB2

PB3

 

PB5

PB1

 

PB3

PB4

 
 

PB2

PB3

 

PB5

PB1

PB2

PB3

PB4

PB5

PB1

  

PB4

PB5

 

and I need to have from that this Table:

X

PB1

PB1

 

PB1

 

PB1

PB1

 

PB2

PB2

 

PB2

PB2

PB3

 

PB3

PB3

PB3

PB3

PB4

PB4

 

PB4

 

PB4

PB4

PB5

 

PB5

 

PB5

PB5

PB5

 

In the mainwhile I have found by myself a solution that sound as this:

 

In Power Query from an empty query I have extracted columns of my interest and created my tables with:

query1= Table.SelectColumns(TableX,{"PB1"})

query2= Table.SelectColumns(TableX,{"PB2"})

and so on.

At this point I can use Append Query and I have opteined my requirements!

 

AgoZ

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.