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
SR1
Helper I
Helper I

Need help on calculating measure

I am trying to create a new measure for the below scenario.

 

1) I want to count the number of people that are inside a building .

Formula I used

PeopleInside = CALCULATE(DISTINCTCOUNT(Table[person_id]),isblank(Table[exit_time]))
This works perfect.

 

2) I want to distinct count the number of people that left the building.

Formula I used 

PeopleOutside = CALCULATE(DISTINCTCOUNT(Table[person_id]),Table[exit_time] <> BLANK())

 

Here comes the problem :

person_idperson_nameenter_timeexit_time
100xyz04/06/2018 9:46:41 AM04/06/2018 6:08:13 PM
100xyz04/06/2018 6:30:11 PM 

In this case, PeopleOutside should be showing 0 because the person is inside the building but my formula shows 1 for both PeopleInside and PeopleOutside.

 

Could someone please help. Thanks!

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @SR1,

 

We can filter out these person still inside. Try this formula, please.

Measure =
VAR stillIn =
    CALCULATETABLE ( VALUES ( Table1[person_id] ), ISBLANK ( 'Table1'[exit_time] ) )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table1[person_id] ),
        FILTER (
            'Table1',
            ISBLANK ( 'Table1'[exit_time] ) = FALSE ()
                && NOT Table1[person_id] IN stillIn
        )
    )

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-jiascu-msft
Employee
Employee

Hi @SR1,

 

Did it work?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @SR1,

 

We can filter out these person still inside. Try this formula, please.

Measure =
VAR stillIn =
    CALCULATETABLE ( VALUES ( Table1[person_id] ), ISBLANK ( 'Table1'[exit_time] ) )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table1[person_id] ),
        FILTER (
            'Table1',
            ISBLANK ( 'Table1'[exit_time] ) = FALSE ()
                && NOT Table1[person_id] IN stillIn
        )
    )

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.