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
talhaparvaiz
Helper I
Helper I

using union in powerBI

Hi Experts,

I am downloading data from SurveyMonkey through the plugin, and the objective is to create PowerBI reports and dashboards using the data.

 

My table is in the following format

 

UserName     Application1     Application 2     Application3

ABC               AppA                AppB                 AppC

DEF               AppF                 AppE                  null

GHI               AppA                AppB                  null

JKL                AppE                 null                    null

 

Reports' requirement is to identify users and count of applications, something like this

 

ABC   3

DEF   2

GHI  2

JKL 1

 

Is there a way we can convert the original table to show something like this (and create reports sourcing it)

 

ABC               AppA               

ABC               AppB                 

ABC               AppC

DEF               AppF 

DEF               AppE 

GHI               AppA 

 

In a DB, I would have done it using union statements, as an example

select UserName,  Application1   as APP

union

select UserName,  Application2   as APP

union

select UserName,  Application3   as APP

 

any suggestions on how to do it in power BI

 

Thanks in advance

...

1 ACCEPTED SOLUTION

Hi @talhaparvaiz 

Yep no problem.

1. Start by loading your data into Power BI/Power Query and open the query editor (click Transform Data on the Ribbon in PBI).  Your source data looks like this

srcd.png

 

2. Select the 3 columns and then right click on one of the column headers.  Choose Unpivot Columns from the menu

unpiv.png

 

3. You end up with this

unres.png

 

4. Filter null values out of the Value column

filt-null.png

 

filt-res.png

 

5. Delete the Attribute column

del-attr.png

 

Regards

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

3 REPLIES 3
talhaparvaiz
Helper I
Helper I

this is exactly what I was looking for... Can you please walk me through the steps (or direct me to the tutorial) so that I can understand the process.

 

Thanks again

Hi @talhaparvaiz 

Yep no problem.

1. Start by loading your data into Power BI/Power Query and open the query editor (click Transform Data on the Ribbon in PBI).  Your source data looks like this

srcd.png

 

2. Select the 3 columns and then right click on one of the column headers.  Choose Unpivot Columns from the menu

unpiv.png

 

3. You end up with this

unres.png

 

4. Filter null values out of the Value column

filt-null.png

 

filt-res.png

 

5. Delete the Attribute column

del-attr.png

 

Regards

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @talhaparvaiz 

Download this sample PBIX file with code

You can unpivot the data in Power Query

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRciwocIRQThDKWSlWJ1rJxdUNwoVSrkAqrzQnByzp7uGJoRMu6eXtg6YFJhkLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UserName = _t, App1 = _t, App2 = _t, App3 = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"UserName"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> "null")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute"})
in
    #"Removed Columns"

 

 

unp.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.