Forum Discussion
Filtering based on parent grouping
Hi, ruiner
Thanks for your quick reponse!
I'm very sorry that there is no way to understand your arithmetic logic.
Accoridng to the sample data , when you filter the [employee group]=2 , it shows the table like this:
And then the [DistinctEmploymentCount] measure seems to calculate the sum of the "EmployeeCode" where the [EmployeeStatusCount]=1 in the 'Headcount' Table.
And from your sample data , i still do not understand how to get the table when filter the [employee group]=2?
Can you give me the sample data in 'Headcount' Table and explain the detailed calculation for the table you want to get in the end?
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
The slicer in that example is set to [EmployeeGroupId]=1, it is filtering out the records where the group is 2.
Here is the SQL query I am trying to replicate if that helps.
select
CompanyId,
FiscalPeriodId,
EmployeeStatusId,
count(distinct EmployeeCode) Total
from
(
select
CompanyId,
FiscalPeriodId,
EmployeeCode,
iif(
(
select
count(distinct p2.EmployeeStatusId)
from
PositionSample p2
where
p2.FiscalPeriodId = p.FiscalPeriodId and
p2.CompanyId = p.CompanyId and
p2.EmployeeGroupId = p.EmployeeGroupId and
p2.EmployeeCode = p.EmployeeCode
) = 1,
p.EmployeeStatusId,
null
) as EmployeeStatusId
from
PositionSample p
where
p.EmployeeGroupId = 1 and
p.FiscalPeriodId in (1) and
p.CompanyId in (1)
group by
CompanyId,
FiscalPeriodId,
EmployeeCode,
EmployeeStatusId
) sub
group by
CompanyId, FiscalPeriodId, EmployeeStatusId
;
The status id is unchanged if the employee only belongs to one status. They may have more than one position within this status and it will still be unchanged.
The status id is null in the query if the employee holds positions under more than one status within the filter set. I would like to rewrite the status to a different id in DAX.