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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
sraj
Responsive Resident
Responsive Resident

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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

 

sraj
Responsive Resident
Responsive Resident

@Anonymous  - 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.

Anonymous
Not applicable

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
Responsive Resident
Responsive Resident

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

Anonymous
Not applicable

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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