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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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