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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.