Forum Discussion

pelangi's avatar
pelangi
Helper I
4 years ago
Solved

Equivalent of SQL Inner Query in DAX for Employee Mutation

So the problem is this. Every week I have to create a report about the position of each employee in each department. So basically I record them in Excel with this format. Field1 : CurrentWeekNumbe...
  • v-jingzhang's avatar
    4 years ago

    Hi pelangi 

     

    You can try this measure. If the employee are in two positions in a week (when the start date is not a week start date), it will display both positions in that week. _previousPosition and _nextPosition variables represent the two positions. You can modify the returned result per your need. 

    Department Position =
    VAR _weekStartDate = MIN ( 'Date'[Date] )
    VAR _weekEndDate = MAX ( 'Date'[Date] )
    VAR _onlyPosition =
        MAXX (
            FILTER (
                Employee,
                Employee[StartDate] <= _weekStartDate
                    && (
                        _weekEndDate <= Employee[FinishDate]
                            || ISBLANK ( Employee[FinishDate] )
                    )
            ),
            Employee[Department]
        )
    VAR _previousPosition =
        MAXX (
            FILTER (
                Employee,
                _weekStartDate <= Employee[FinishDate]
                    && _weekEndDate > Employee[FinishDate]
            ),
            Employee[Department]
        )
    VAR _nextPosition =
        MAXX (
            FILTER (
                Employee,
                _weekStartDate < Employee[StartDate]
                    && _weekEndDate >= Employee[StartDate]
            ),
            Employee[Department]
        )
    RETURN
        IF (
            NOT ( ISBLANK ( _previousPosition ) ),
            _previousPosition & "," & _nextPosition,
            _onlyPosition
        )
    

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.