Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have a piece of code in DAX that "works" perfectly. However if I add an extra filter inito the code, then it goes a bit pear shaped. For the life of me I ave tried to fix this and failed miserably. Any suggestions welcome 🙂
The code below. This works perfect - counting staff at month end each month. BUT, only if no slicers are active to filter "Business Area".
EmployeesAtEndOfMonth =
IF(
ISFILTERED('staffmaster'[Business Area]),
CALCULATE(
DISTINCTCOUNT('staffmaster'[Unique ID]),
FILTER(
ALL('staffmaster'),
'staffmaster'[Business Area] IN VALUES ('STAFFMASTER'[Business Area]) &&
('staffmaster'[End Date] >= MAX('Date'[End of Month]) || ISBLANK('staffmaster'[End Date])) &&
'staffmaster'[Start Date] <= MAX('Date'[End of Month])
)
),
CALCULATE(
DISTINCTCOUNT('staffmaster'[Unique ID]),
FILTER(
ALL('staffmaster'),
('staffmaster'[End Date] >= MAX('Date'[End of Month]) || ISBLANK('staffmaster'[End Date])) &&
'staffmaster'[Start Date] <= MAX('Date'[End of Month])
)
)
)
If I select a "Business Area" in a slicer. Lets for example say "HR", then I get some odd behavour. If the month in question did not have someone new starting that month, it doesnt count anything for that month.
Example -
Jan23 - 30 staff (Powerbi counts 30 staff because someone new started month)
Feb 23 - 37 staff (because at least one new start that month)
Mar23 - 0 staff (no new starts this month so powerbi just counts the month as blank)
April 23 - 35 staff (at least one new start)
May23 - 0 staff (no new starts this month)
Jun23 - 36 staff (at least one new start)
So the only correlation between the blanks is that we had no new starts in "HR" in the blank months. I have check against other Business Areas and the correlation seems to hold up. ANy business area where we had a least one new start each month, has no blanks. Any business area where we had no new starts in any month, those months show a blank.
Im no PBI master and I expect the answer is simple enough, but im stumped.
As for data tables the data comes from:
Date Table - marked as date table, called "Date". Has columns for [Date], [End of Month]
Staff table - called Staffmaster. Has columns for [Unique ID], [Start Date], [End Date], [Business Area].
All i want to do is show a number of staff employed on the last day of each month, and be able to filter it by business area.
Solved! Go to Solution.
OK, I have no idea why it was counting that way. And I have rewritten the entire piece to use @amitchandak code from his youtube page. It works perfect under all tests now.
Amits Youtube Linky
OK, I have no idea why it was counting that way. And I have rewritten the entire piece to use @amitchandak code from his youtube page. It works perfect under all tests now.
Amits Youtube Linky
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |