cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kjartank Helper II
Helper II

Using filter on UNION

Hi.

 

I have been using the "UNION" function to get my charts to be more manageable and am in need of a filter on these tables. The code I've been using looks like this.

Satisfaction Score = UNION (
SELECTCOLUMNS (Tabel1; "Attribute"; "01. Check-in"; "Answer"; Tabel1[Check-in] );
SELECTCOLUMNS (Tabel1; "Attribute"; "02. Room"; "Answer"; Tabel1[Room] );
SELECTCOLUMNS (Tabel1; "Attribute"; "03. Service"; "Answer"; Tabel1[Service] );
SELECTCOLUMNS (Tabel1; "Attribute"; "04. Entertainment"; "Answer"; Tabel1[Entertainment] );
SELECTCOLUMNS (Tabel1; "Attribute"; "05. Cleanliness"; "Answer"; Tabel1[Cleanliness] );
SELECTCOLUMNS (Tabel1; "Attribute"; "06. Childfriendly facilities"; "Answer"; Tabel1[Chilfriendly facilities] );
SELECTCOLUMNS (Tabel1; "Attribute"; "07. Prices"; "Answer"; Tabel1[Prices] );
SELECTCOLUMNS (Tabel1; "Attribute"; "08. Overall experience"; "Answer"; Tabel1[Overall Experience] )
 )

I need to filter ALL the variables on the highest value of a variable called "Period". How would I go about implementing that in the UNION function?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User IV
Super User IV

Re: Using filter on UNION

You would use FILTER in your first parameter. So,

 

SELECTCOLUMNS (FILTER(Table1,[Period] = MAX([Period])); "Attribute";...

Something along those lines. Would need sample data to get specfic.

 

You might also want to create a variable where you filter your table and return it and then use that variable in place of Table1 in your SELECTCOLUMNS. Would be more efficient that way.


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Super User IV
Super User IV

Re: Using filter on UNION

You would use FILTER in your first parameter. So,

 

SELECTCOLUMNS (FILTER(Table1,[Period] = MAX([Period])); "Attribute";...

Something along those lines. Would need sample data to get specfic.

 

You might also want to create a variable where you filter your table and return it and then use that variable in place of Table1 in your SELECTCOLUMNS. Would be more efficient that way.


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

View solution in original post

Microsoft v-huizhn-msft
Microsoft

Re: Using filter on UNION

Hi @kjartank,

Please follow the @Greg_Deckler said, filter the table using the highest value of a variable called "Period". Then use the filter table in your formula, don't hesitate to ask if you have any other issue.

Best Regards,
Angelia

kjartank Helper II
Helper II

Re: Using filter on UNION

hi @v-huizhn-msft

 

I've tried the solution that @Greg_Deckler suggested and I got an error. I'm not sure why, but the error message reads "Cannot identify the table that contains [period] column."

Highlighted
kjartank Helper II
Helper II

Re: Using filter on UNION

Hi @v-huizhn-msft and @Greg_Deckler

 

An embarrasing fault from my side. The solution that @Greg_Deckler works just fine. I should have replaced the comma with a semicolon, which I didn't do at first. So please accept my apologies. Thanks a lot. It runs beautifully now!

Super User IV
Super User IV

Re: Using filter on UNION

@kjartank - Apologies for the comma versus semi-colon! Still haven't mastered those localization differences!


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

bsas Helper V
Helper V

Re: Using filter on UNION

Hi @Greg_Deckler,

 

How I can create such variable (filtered table based on slicer) and then use it selectcolumns?

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors