cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sraj
Post Patron
Post Patron

MEASURE FOR OR CONDITION BETWEEN ROWS

 

Hi,

 

Looking for a measure to show the users who could either have ENFORCED or ENABLED in the same column and table,  Can someone please advise?

 

sraj_0-1646414377513.png

 

1 ACCEPTED SOLUTION
Ville
Helper I
Helper I

If you only have those two statuses in the list, you can simply count the rows of the table and filter to only show users with 2 rows present.

 

If you have more statuses, this measure will do the trick in a list view like this:

_User is both enabled and enforced = 

CALCULATE(
    COUNTROWS('Table'),
    FILTER('Table',
        'Table'[Status] = "ENFORCED" ||
        'Table'[Status] = "ENABLED"
    )
)

 

 

When only showing users, not their statuses, the measure above will calculate 2 rows for each user with both ENFORCED and ENABLED as statuses.

Ville_0-1646766120093.png



However this does not work if you intend to also show the status in the list, as the row will go back to 1 again for all.
Another solution would be to create a separate User table for all your distinct users.
Create a calculated table like this:

Users = DISTINCT('Table'[User])

 


You can then create a calculated column that will turn true or false if the user has both of these statuses:

 

IsBothEnabledAndEnforced = 

// Count how many rows the user has that is either enforced or enabled
CALCULATE(
    COUNTROWS('Table'),
    FILTER('Table',
        Users[User] = 'Table'[User] &&
        OR(
            'Table'[Status] = "ENFORCED",
            'Table'[Status] = "ENABLED"
        )
    )
)
// Claim it's equal to 2, meaning it will turn true for any users with both statuses
= 2

 

Ville_1-1646767049576.png

 

 

Create a relationship between your tables like this:

Ville_2-1646767076721.png

 

 

Create your list using the User from the dimensional table of users and the status from the other table. Use your column from the user table as filter to only show those with both statuses

Ville_3-1646767155798.png

 

View solution in original post

5 REPLIES 5
Ville
Helper I
Helper I

If you only have those two statuses in the list, you can simply count the rows of the table and filter to only show users with 2 rows present.

 

If you have more statuses, this measure will do the trick in a list view like this:

_User is both enabled and enforced = 

CALCULATE(
    COUNTROWS('Table'),
    FILTER('Table',
        'Table'[Status] = "ENFORCED" ||
        'Table'[Status] = "ENABLED"
    )
)

 

 

When only showing users, not their statuses, the measure above will calculate 2 rows for each user with both ENFORCED and ENABLED as statuses.

Ville_0-1646766120093.png



However this does not work if you intend to also show the status in the list, as the row will go back to 1 again for all.
Another solution would be to create a separate User table for all your distinct users.
Create a calculated table like this:

Users = DISTINCT('Table'[User])

 


You can then create a calculated column that will turn true or false if the user has both of these statuses:

 

IsBothEnabledAndEnforced = 

// Count how many rows the user has that is either enforced or enabled
CALCULATE(
    COUNTROWS('Table'),
    FILTER('Table',
        Users[User] = 'Table'[User] &&
        OR(
            'Table'[Status] = "ENFORCED",
            'Table'[Status] = "ENABLED"
        )
    )
)
// Claim it's equal to 2, meaning it will turn true for any users with both statuses
= 2

 

Ville_1-1646767049576.png

 

 

Create a relationship between your tables like this:

Ville_2-1646767076721.png

 

 

Create your list using the User from the dimensional table of users and the status from the other table. Use your column from the user table as filter to only show those with both statuses

Ville_3-1646767155798.png

 

@Ville  - Sorry for not responding earlier, just got to it today.  What if the I have two columns of names, as first name and last name instead of just user?  Please advise.

There are 2 ways I would do this.

1. I simply concatinate the first and last name into a new column and make the new table based on these distinct values

2. Using Selectcolumns-formula you can create the new user table with distinct values from both first and last name in separate columns

sraj
Post Patron
Post Patron

Some user could have both enforced or enabled and some could have just one.

Ville
Helper I
Helper I

What do you need the measure for? Can't you just drop the users in a visual table on the canvas and apply a filter by draging the Status-field to the Filter-pane and select Enforced or Enabled?

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

Power BI Dev Camp Session 25 with aka link 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, August 25 at 11a PDT for a great session with Ted Pattison!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors