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

Union query change field names

I have a query that appends the distinct values from 3 columns into a single field in a new table using a Union . The field names in the source table are

 

ES_CLUSTER_FIN

SUB_CLUSTER

pi_email_engagement_segment_fk

 

The new table has two columns Type (which I've defined in the query) and ES_CLUSTER_FIN which is the name of the first field in the UNION. How do I change the query so I can define the name of this second field in the table created? (instead of it just taking the nam of the first field in the union)

 

Here is the sytnax::

 

 

Table =
var eng_cluster = CROSSJOIN(ROW("Type","Engagement Cluster"), VALUES( 'mc contact_density_weekly_volume_campaign'[ES_CLUSTER_FIN]))
var eng_sub_cluster = CROSSJOIN(ROW("Type","Engagement Sub-cluster"), VALUES('mc contact_density_weekly_volume_campaign'[SUB_CLUSTER]))
var email_engagement = CROSSJOIN(ROW("Type","Email Engagement"), VALUES('mc contact_density_selection_join'[pi_email_engagement_segment_fk]))
return UNION(UNION(eng_cluster,eng_sub_cluster), email_engagement)

1 ACCEPTED SOLUTION
zukkster
Frequent Visitor

OK I worked it out.

 

Moving the return and adding an additional SELECTCOLUMNS renames the field ES_CLUSTER_FIN to "Type Desc"

 

Table =
var eng_cluster = CROSSJOIN(ROW("Type","Engagement Cluster"), VALUES( 'mc contact_density_weekly_volume_campaign'[ES_CLUSTER_FIN]))
var eng_sub_cluster = CROSSJOIN(ROW("Type","Engagement Sub-cluster"), VALUES('mc contact_density_weekly_volume_campaign'[SUB_CLUSTER]))
var email_engagement = CROSSJOIN(ROW("Type","Email Engagement"), VALUES('mc contact_density_selection_join'[pi_email_engagement_segment_fk]))
var union_table = UNION(UNION(eng_cluster,eng_sub_cluster), email_engagement) return SELECTCOLUMNS(union_table,"Type",[Type],"Type Desc",[ES_CLUSTER_FIN])

View solution in original post

1 REPLY 1
zukkster
Frequent Visitor

OK I worked it out.

 

Moving the return and adding an additional SELECTCOLUMNS renames the field ES_CLUSTER_FIN to "Type Desc"

 

Table =
var eng_cluster = CROSSJOIN(ROW("Type","Engagement Cluster"), VALUES( 'mc contact_density_weekly_volume_campaign'[ES_CLUSTER_FIN]))
var eng_sub_cluster = CROSSJOIN(ROW("Type","Engagement Sub-cluster"), VALUES('mc contact_density_weekly_volume_campaign'[SUB_CLUSTER]))
var email_engagement = CROSSJOIN(ROW("Type","Email Engagement"), VALUES('mc contact_density_selection_join'[pi_email_engagement_segment_fk]))
var union_table = UNION(UNION(eng_cluster,eng_sub_cluster), email_engagement) return SELECTCOLUMNS(union_table,"Type",[Type],"Type Desc",[ES_CLUSTER_FIN])

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.