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
Anonymous
Not applicable

Replacement for Union in Direct Query

Hello everyone,

 

If I have this kind of table:

medwong_0-1619778260627.png

It is confirmed, all rows will have same value on each columns.

 

Initially I want to Transpose this data To be come simply like this :

medwong_1-1619778421608.png

With an addition of 1 column, so probably like this :

medwong_2-1619778497920.png

The ABC in column [Field] is actually can be the column name of 1st table, I just want to make it easier.

 

Is this possible with Direct Query Mode ?

 

At first I thought a UNION like this :

 

UNION( 			
SELECTCOLUMNS('Table', "Type", "A", "Description", 'Table'[Column1]),			
SELECTCOLUMNS('Table', "Type", "B", "Description", 'Table'[Column2]),			
SELECTCOLUMNS('Table', "Type", "C", "Description", 'Table'[Column3]),			

 

 

But it turns out, this UNION forced me to switch to Import Mode. Any replacement trick to make this possible in Direct Query ?

 

Thanks

2 ACCEPTED SOLUTIONS
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous  , 

 

According to the official document , Calculated tables aren't supported:

v-yalanwu-msft_0-1620124844521.png

So,  you could create the A, B, C three columns  as three measures, and then use “union() “to achieve , as follows:

First: create three measures

Ameasure = MAX('Table'[A])
BMeasure = MAX('Table'[B])
Cmeasure = MAX('Table'[C])

Then create new table:

newTable =
DISTINCT (
    UNION (
        SELECTCOLUMNS ( 'Table', "Type", "A", "Description", [Ameasure] ),
        SELECTCOLUMNS ( 'Table', "Type", "B", "Description", [BMeasure] ),
        SELECTCOLUMNS ( 'Table', "Type", "C", "Description", [Cmeasure] )
    )
)

The final output is shown below:

 v-yalanwu-msft_1-1620124844523.png

Last, If we create a virtual table with union(), the storage mode will change to mixed mode.

v-yalanwu-msft_2-1620124844525.png

 

Best Regards,
Community Support Team_ Yalan Wu
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

Hi, @Anonymous 

 

You could see my pbix file. Your data source is still in DQ mode. Since you created a virtual table with union(), it is mix(), which does not affect your data source itself.

 

Best Regards,
Community Support Team_ Yalan Wu
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

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous  , 

 

According to the official document , Calculated tables aren't supported:

v-yalanwu-msft_0-1620124844521.png

So,  you could create the A, B, C three columns  as three measures, and then use “union() “to achieve , as follows:

First: create three measures

Ameasure = MAX('Table'[A])
BMeasure = MAX('Table'[B])
Cmeasure = MAX('Table'[C])

Then create new table:

newTable =
DISTINCT (
    UNION (
        SELECTCOLUMNS ( 'Table', "Type", "A", "Description", [Ameasure] ),
        SELECTCOLUMNS ( 'Table', "Type", "B", "Description", [BMeasure] ),
        SELECTCOLUMNS ( 'Table', "Type", "C", "Description", [Cmeasure] )
    )
)

The final output is shown below:

 v-yalanwu-msft_1-1620124844523.png

Last, If we create a virtual table with union(), the storage mode will change to mixed mode.

v-yalanwu-msft_2-1620124844525.png

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

Anonymous
Not applicable

Hi,

 

Thanks, but unfortunately I must use pure DIrect Query.

 

rgds,

Hi, @Anonymous 

 

You could see my pbix file. Your data source is still in DQ mode. Since you created a virtual table with union(), it is mix(), which does not affect your data source itself.

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

amitchandak
Super User
Super User

@Anonymous , As far as I understood this transformation is only possible in import mode

Anonymous
Not applicable

So, no TRANSPOSE.. and also no UNION...

No other tricks ? 😅

@Anonymous , I was think of usin userealtionship with a table having distinct names (that can be as import mode table if needed)

But that depend of requirements  https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in-power-bi

 

In this manner we can take total from three columns

 

also run time union in a measure, depend on need

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.