CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2023-11-22
by Sam Nseir

Original Post

Original - Posted on 2023-11-21
by Sam Nseir



            
Present in both answers; Present only in the new answer; Present only in the old answer;

If you want the average between a selected date with Today's then:
```dax 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) )
Employed Staff Count - Today = CALCULATE( [Employed Staff Count], FILTER(ALL('Calendar'), 'Calendar'[Date] = TODAY() ) )
Employed Staff Count - AVG = DIVIDE( [Employed Staff Count] + [Employed Staff Count - Today], 2 ) ```
And if you want the daily average across a selection of dates then: ```dax Employed Staff Count - AVG Daily = var tot = SUMX( VALUES('Calendar'[Date]), [Employed Staff Count] ) var cnt = COUNTROWS( VALUES('Calendar'[Date]) ) return DIVIDE( tot, cnt ) ```

----------
### Supplemental If you wanted to look at this at a Monthly (or weekly, or quarterly) grain and your `Calendar` date table has a column for that grain (eg column `Year-Month = FORMAT([Date], "yyyy-MM")`. Then the measure `[Employed Staff Count]` will still work but it will only give employee count of those who have been employed throughout that grain period.
If you wanted a measure for total employee count in that grain whether partial or fully employed in that grain, then you would need: ```dax Employed Staff Count Partial = var minD = MIN('Calendar'[Date]) var maxD = MAX('Calendar'[Date]) RETURN CALCULATE( DISTINCTCOUNT('STAFFMASTER'[Unique ID]), 'STAFFMASTER'[Current Employment: Start Date] <= maxD && ( 'STAFFMASTER'[End Date] >= minD || ISBLANK('STAFFMASTER'[End Date]) ), CROSSFILTER('Calendar'[Date], STAFFMASTER[Current Employment: Start Date], None) ) ``` Note how the logic changes to startDate `<= maxD` and endDate `>= minDate`
Whether your want full or partial count, you can then have monthly avg like: ```dax // fully employed for each month Employed Staff Count - AVG Monthly = var tot = SUMX( VALUES('Calendar'[Year-Month]), [Employed Staff Count] ) var cnt = COUNTROWS( VALUES('Calendar'[Year-Month]) ) return DIVIDE( tot, cnt )
// partially employed for each month Employed Staff Count Partial - AVG Monthly = var tot = SUMX( VALUES('Calendar'[Year-Month]), [Employed Staff Count Partial ] ) var cnt = COUNTROWS( VALUES('Calendar'[Year-Month]) ) return DIVIDE( tot, cnt ) ```
Assuming you have a relationship between `'Calendar'[Date]` 1-* `'STAFFMASTER'[Current Employment: Start Date]`, then you could simply have: ```dax 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) ) ```
And if you don't have a relationship then your can remove `, CROSSFILTER(...)` part.

        
Present in both answers; Present only in the new answer; Present only in the old answer;