Forum Discussion
Show rows based on selected filter in another column
I have a table as below with a filter for Project. I want to display, in a table, all the Projects with the same Parent when the Project selected equals a Parent. Example: Filter Project on "bbb", the table returns 1b, 2b, 3b, 4b as they all have the Parent "bbb". I don't want to filter on the "Parent" as I want to be able to show Projects that don't have a Parent in the table too.
| business area | Project | Parent |
| 2 | 1b | bbb |
| 5 | 2b | bbb |
| 7 | 3b | bbb |
| 14 | 4b | bbb |
| 20 | bbb | ddd |
| 22 | 1d | ddd |
| 24 | 2d | ddd |
| 1 | 3d | ddd |
| 3 | 4d | ddd |
| 4 | 5d | ddd |
| 6 | 6d | ddd |
| 8 | 7d | ddd |
| 9 | 8d | ddd |
| 10 | ddd | xxx |
| 12 | 1x | xxx |
| 13 | 2x | xxx |
| 15 | 3x | xxx |
| 16 | 4x | xxx |
| 17 | 5x | xxx |
Hi Rani301170 ,
To achieve this in Power BI, you can first create a disconnected slicer table using the formula Project Selector = DISTINCT('YourTable'[Project]). This table will serve as the slicer so that selecting a project doesn't directly filter your main table, giving you more control over the logic.
Next, create a calculated table that returns all the projects sharing the same Parent as the selected project, but only when the selected project is a Parent. Otherwise, it will simply return the selected project. Use the following DAX for the calculated table:
Filtered Projects = VAR SelectedProject = SELECTEDVALUE('Project Selector'[Project]) VAR SelectedParent = CALCULATE( MAX('YourTable'[Parent]), 'YourTable'[Project] = SelectedProject ) VAR IsSelectedAParent = CALCULATE( COUNTROWS('YourTable'), 'YourTable'[Parent] = SelectedProject ) > 0 RETURN IF( IsSelectedAParent, FILTER( 'YourTable', 'YourTable'[Parent] = SelectedProject ), FILTER( 'YourTable', 'YourTable'[Project] = SelectedProject ) )This logic ensures that if a user selects "bbb", which is a Parent, the table will return all projects where the Parent is "bbb" (like 1b, 2b, 3b, 4b). If the selected project isn't a Parent, it will just return that project itself. You can use this calculated table in your visual to display the desired filtered results.
Best regards,
4 Replies
- DataNinja777Super User
Hi Rani301170 ,
To achieve this in Power BI, you can first create a disconnected slicer table using the formula Project Selector = DISTINCT('YourTable'[Project]). This table will serve as the slicer so that selecting a project doesn't directly filter your main table, giving you more control over the logic.
Next, create a calculated table that returns all the projects sharing the same Parent as the selected project, but only when the selected project is a Parent. Otherwise, it will simply return the selected project. Use the following DAX for the calculated table:
Filtered Projects = VAR SelectedProject = SELECTEDVALUE('Project Selector'[Project]) VAR SelectedParent = CALCULATE( MAX('YourTable'[Parent]), 'YourTable'[Project] = SelectedProject ) VAR IsSelectedAParent = CALCULATE( COUNTROWS('YourTable'), 'YourTable'[Parent] = SelectedProject ) > 0 RETURN IF( IsSelectedAParent, FILTER( 'YourTable', 'YourTable'[Parent] = SelectedProject ), FILTER( 'YourTable', 'YourTable'[Project] = SelectedProject ) )This logic ensures that if a user selects "bbb", which is a Parent, the table will return all projects where the Parent is "bbb" (like 1b, 2b, 3b, 4b). If the selected project isn't a Parent, it will just return that project itself. You can use this calculated table in your visual to display the desired filtered results.
Best regards,
- AnonymousNot applicable
Hi Rani301170,
Thank you for reaching out in Microsoft Community Forum.
Thank you DataNinja777 for the helpful response.
As suggested by DataNinja777, I hope this information was helpful. Please let me know if you have any further questions or you'd like to discuss this further. If this answers your question, please "Accept as Solution" and give it a 'Kudos' so others can find it easily.
Please continue using Microsoft community forum.
Regards,
Pavan. - AnonymousNot applicable
Hi Rani301170,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please "Accept as Solution" and give a 'Kudos' so other members can easily find it.
Thank you,
Pavan. - AnonymousNot applicable
Hi Rani301170,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Please continue using Microsoft community forum.
Thank you,
Pavan.