Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.