Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
fabiocovre
Advocate I
Advocate I

Measure to indicate Active/Excluded people

Hi,

I need to create a measure to indicate if a person is active or excluded of the data. To that, I have a census fact table where exists the users name being repeated every month. What I want to do is case a user don't be present in the last month of this fact table, I indicate him as Excluded, otherwise, she remains Active.

1.PNGAbove is an example what I did. The highlighted user is "Excluded" because the last time she appeared in the census fact table was on nov/2021.

 

The problem that I'm facing is when I filter a specific month, for example sep/21 and indicates that she's Active now. What I need is that, independent of what filter I'm using, the DAX formula always return her a Excluded status based on the last month of the model (apr/22 in this case).

 

2.PNG

Thank you!

Fabio

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi, @fabiocovre,

I think a measure like this would do the trick:

Is active/inactive =
VAR _lastMonth =
    CALCULATE ( MAX ( 'Table'[Month] ), REMOVEFILTERS () )
VAR _user =
    SELECTEDVALUE ( 'Users'[User] )
VAR _isActiveLastMonth =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[User] = _user && 'Table'[Month] = _lastMonth )
    )
VAR _result =
    IF (
        ISBLANK ( _user ),
        BLANK (),
        IF (
            ISBLANK ( _isActiveLastMonth )
                && NOT ( ISBLANK ( SELECTEDVALUE ( Users[User] ) ) ),
            "Inactive",
            "Active"
        )
    )
RETURN
    _result

 

as you have not provided a sample report, I have used some generic names for table and columns, you will of course need to adapt this to your model.

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

View solution in original post

1 REPLY 1
sturlaws
Resident Rockstar
Resident Rockstar

Hi, @fabiocovre,

I think a measure like this would do the trick:

Is active/inactive =
VAR _lastMonth =
    CALCULATE ( MAX ( 'Table'[Month] ), REMOVEFILTERS () )
VAR _user =
    SELECTEDVALUE ( 'Users'[User] )
VAR _isActiveLastMonth =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[User] = _user && 'Table'[Month] = _lastMonth )
    )
VAR _result =
    IF (
        ISBLANK ( _user ),
        BLANK (),
        IF (
            ISBLANK ( _isActiveLastMonth )
                && NOT ( ISBLANK ( SELECTEDVALUE ( Users[User] ) ) ),
            "Inactive",
            "Active"
        )
    )
RETURN
    _result

 

as you have not provided a sample report, I have used some generic names for table and columns, you will of course need to adapt this to your model.

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.