DAX - Miscounting

hmltnangel

Active Member
Joined
Aug 25, 2010
Messages
290
Office Version
  1. 365
Platform
  1. Windows
Hi all. I have tried a few different route for this one, and cant quite get it right. I am hopeful you kind people will fix this.

I have a Date/Calendar table created called "Date" with a column of dates. I have a table with all staff data contained in it, called StaffCounts. This contains columns for "Name", "Start Date", "End Date".

I want to be able to count how many people were employed on a specific date that I can select via filters, or Slicers.

The code I have used is as follows: (basically an adaptation of this - Open Tickets)

Code:
Staff on Date =
CALCULATE(
    COUNTROWS(staffcounts),
    FILTER(
        staffcounts,
        STAFFcounts[Current Employment: Start Date] <= MAX('Date'[Date]) &&
        (staffmaster[Current Employment: end date] >= MAX('Date'[Date]) || ISBLANK(staffcounts[Current Employment: end date]))
    )
)

Now what I think is happening, is that its counting how many people started on a filtered date, rather than the number of people employed on a set date. Any suggestions?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
A little crossposted one. (Not one for doing that but at least it worked this time)

I managed to resolve this with the use of the suggestion here:


And the code:
Code:
Employed Staff Count =
  var minD = MIN('Calendar'[Date])
  var maxD = MAX('Calendar'[Date])
  RETURN CALCULATE(
    DISTINCTCOUNT('STAFFMASTER'[Unique ID]),
    'STAFFMASTER'[Current Employment: Start Date] <= minD &&
    ( 'STAFFMASTER'[End Date] >= maxD || ISBLANK('STAFFMASTER'[End Date]) ),
    CROSSFILTER('Calendar'[Date], STAFFMASTER[Current Employment: Start Date], None)
  )

This works perfectly.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top