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
anjbauer1993
Frequent Visitor

Unpivoting keys from multiple categories into one column

I am trying to transform an Excel worksheet containing a company's health insurance coverage for its employees. There are three tiers of coverage and four levels of each of those. I was able to transform the insurance dimension without any trouble, it looks like

dim_insurance

With M1, M2, M3 being the three tiers, and a, b, c, d representing who it applies to (Employee, Spouse, etc).

 

Below is a portion of the fact table,

fact

The rows are unique on Employee. As you can see, an employee can have multiple variations of insurance at once. I filtered out null values in M1 - a just to make things easier to visualize. I'm hoping to unpivot the M* - * columns into one long column, with multiple rows for employees that have multiple selections. I'm able to create the same type of key as in the dimension table, but I haven't been able to get them into one column. I have a feeling this involves the unpivot function but I have had no luck so far. Any help or advice is greatly appreciated.

1 ACCEPTED SOLUTION
anjbauer1993
Frequent Visitor

I was able to solve this but I didn't end up using unpivot. I converted the values into the respective keys, then added a custom column =  List.Union ( { {col_1}, {col_2}, ... , {col_n} } ) which I then expanded into new rows, giving me the desired result

View solution in original post

4 REPLIES 4
anjbauer1993
Frequent Visitor

I was able to solve this but I didn't end up using unpivot. I converted the values into the respective keys, then added a custom column =  List.Union ( { {col_1}, {col_2}, ... , {col_n} } ) which I then expanded into new rows, giving me the desired result

v-yuta-msft
Community Support
Community Support

Hi anjbauer1993,

 



I'm hoping to unpivot the M* - * columns into one long column, with multiple rows for employees that have multiple selections. I'm able to create the same type of key as in the dimension table, but I haven't been able to get them into one column. 

 

To be general, in query editor, click on all columns named M*-*, click Transform-> Unpivot Columns and check if it can meet your reuquirement.

 

Regards,

Jimmy Tao

Ashish_Mathur
Super User
Super User

Hi,

 

Please show your exact expected result.  Also, paste data here such that i can in turn paste that table into an Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Dimension:

DateLevelUserKeyCost
2018-M1-a519.41
2018-M1-b519.41
2018-M1-c289.64
2018-M1-d519.41
2018-M2-a474.34
2018-M2-b474.34
2018-M2-c264.51
2018-M2-d474.34
2018-M3-a623.45
2018-M3-b623.45
2018-M3-c347.65
2018-M3-d623.45

 

 

Fact Table:

DateLastFirstM1 - aM1 - bM1 - cM1 - dM2 - aM2 - bM2 - cM2 - dM3 - aM3 - bM3 - cM3 - d
8/1/2018DoeJohnabcdnullnullnullnullnullnullnullnull
8/1/2018BauerAndrewanullnullnullnullnullnullnullnullnullnullnull
8/1/2018DollinDustinnullnullnullnullabcnullanullnullnull

 

 

And this is the result I am hoping for:

DateLastFirstInsuranceKey
8/1/2018DoeJohn2018-M1-a
8/2/2018DoeJohn2018-M1-b
8/3/2018DoeJohn2018-M1-c
8/4/2018DoeJohn2018-M1-d
8/1/2018BauerAndrew2018-M1-a
8/1/2018DollinDustin2018-M2-a
8/2/2018DollinDustin2018-M2-b
8/3/2018DollinDustin2018-M2-c

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.