Forum Discussion
Filtering based on parent grouping
I have a table laid out like this:
| EmployeeId | CompanyId | FinancialPeriodId | GroupId | StatusId |
| 1 | 10 | 5 | 1 | 1 |
My visual is grouped by company, financial period and then status. I need to have either slicers or filters on company, group and financial period.
The visual needs to display the number of unique employees within each status group. The part I'm having trouble with is an employee should be excluded from this count if they belong to more than one status. I also need to add an additional count of the number of employees excluded for having more than one status.
I currently have a computed table to count the number of statuses an employee has but it's not quite working correctly. I have also read that computed tables aren't responsive to slicers and I need the values to adapt to the slicer settings.
PositionByEmployee =
CALCULATETABLE(
Position,
REMOVEFILTERS(Position[StatusId])
)
Headcount =
SUMMARIZE(
PositionByEmployee, PositionByEmployee[CompanyId], PositionByEmployee[FinancialPeriodId], PositionByEmployee[EmployeeId],
"StatusCount", DISTINCTCOUNT(PositionByEmployee[StatusId])
)
Right now I have a foreign key into the Headcount table that is being used to filter the visual but I am not getting the expected numbers that I can get from a SQL query.
Thanks for your assistance!
14 Replies
- v-yueyunzh-msftCommunity Support
Hi, ruiner Based on your problem and description of the source data, it seems that you created two calculated tables using DAX and slicers for some dimensions: company, group, and financial period, but you find that the calculated table is not responding to the slicer and I need values to fit the slicer settings, right?
If that's the case, I think you can first check which table the dimensions you put in the slicer (company, group, and financial period) come from, and if it's from the table "PositionByEmployee" or the table "Position", I think you need to go to the data model page to check if the field you're currently placing in the visual is from the table "Headcount" that really has a relationship with the table in the slicer:
Because the correct inter-table relationship is the first prerequisite for your slicer to take effect, there is also a prerequisite that the interaction of your slicer needs to be enabled with other visuals, for this setting is in "Edit interaction", you can check this document for details:
Change how visuals interact in a report - Power BI | Microsoft Learn
If you can't find the root cause of the problem after checking, you can upload a download link to your test .pbix file (which does not contain any sensitive data) for further study.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- ruinerFrequent Visitor
Hi, v-yueyunzh-msft ,
Thank you very much for the detailed response. It worked as expected on the sample dataset, but unfortunately it does not give the same numbers as the query on the full dataset.
vs
The second image has the correct numbers. If you're unsure what could be causing this I can provide a larger sanitized dataset if you're able to look into this further for me.
Thanks!
- v-yueyunzh-msftCommunity Support
Hi , ruiner
Thanks for your quick response!
I think it may be that there is some difference between my understanding and your needs. This is my undertand for your need:
If there is a problem with my understanding, you can point it out, and for your problem, you can provide me with a little more data, and then provide some detailed calculation process and results.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- ruinerFrequent Visitor
Thanks v-yueyunzh-msft,
I have a computed column that combines the composite fk and have set the relationship between the tables manually.
The fields in the slicer are from tables related to the Positions table; they are filtering it correctly because I've added a count field to the visual and it is correct.
It is also the only visual at the moment so the only thing I can do with Edit Interactions is turn the slicers off for that one visual.
The numbers displayed in the visual are actually a bit lower than expected from the SQL query. I'm not sure that the computed tables are ungrouping by status id and regrouping by employee id correctly.
Thanks for the help
- v-yueyunzh-msftCommunity Support
Hi , ruiner
This seems to be a DAX question, can you provide more sample data and then provide us with the result data you ultimately want to get on the visual as tabular form ?
If you're filtering by slicers, you can't use a new table, you need to do so with measures. And if you place some fields on the visual, the calculation occurs in the filtered context of the placed field.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- ruinerFrequent Visitor
Hi, v-yueyunzh-msft
Here is a set of sample data for the Position table.
EmployeeCode EmployeeGroupId EmployeeStatusId FiscalPeriodId CompanyId Id 1 1 1 1 1 1 1 1 1 1 1 2 2 1 2 1 1 3 2 2 1 1 1 4 3 1 2 1 1 5 4 1 1 1 1 6 5 1 1 1 1 7 5 1 2 1 1 8 6 1 2 1 1 9 1 2 2 1 1 10 The results from the visual for this sample data look like this. The slicer should be filtering out employee group 2.
DistinctEmployeeCount is produced by this measure.
DistinctEmployeeCount = CALCULATE( COUNT(PositionSample[EmployeeCode]), FILTER( PositionSample, RELATED(Headcount[EmployeeStatusCount]) = 1 ) )And finally, here are the expected results.
Thanks for your help!