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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kl8818
Frequent Visitor

Change Formula

Could someone help me update this formula:

Count employee with 2 or more login: =
VAR _t =
    ADDCOLUMNS (
        VALUES ( 'User Logins'[Employee ID] ),
        "@logincount", CALCULATE ( COUNTROWS ( 'User Logins' ) )
    )
RETURN
    COUNTROWS ( FILTER ( _t, [@logincount] >= 2 ) )

Instead of counting if they just have two or more logins, I'd like to count if they have two or more logins in the last two months, possibly counting one login within each month. (i.e. see first ID in sample data - 1234 - would be someone I would like to count in my formula; not 2345 who has two logins but in the same month)

Sample data set:
 
Logged InID
9/1/20231234
10/3/20231234
10/5/20233456
8/15/20232345
10/5/20232345
10/9/20232345
1 ACCEPTED SOLUTION

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1699680652177.png

 

 

Count Expected result measure: = 
VAR _today =
    TODAY ()
VAR _lastmonthenddate =
    EOMONTH ( _today, -1 )
VAR _twomonthsbeforestartdate =
    EOMONTH ( _today, -3 ) + 1
VAR _monthtable =
    FILTER (
        ADDCOLUMNS (
            'Users Logins',
            "@year-month", EOMONTH ( 'Users Logins'[Logged In], 0 )
        ),
        [@year-month] >= _twomonthsbeforestartdate
            && [@year-month] <= _lastmonthenddate
    )
VAR _summarytable =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( _monthtable, [@year-month], 'Users Logins'[Employee ID] ),
            "@logincount", CALCULATE ( COUNTROWS ( 'Users Logins' ) )
        ),
        [@logincount] >= 1
    )
VAR _idlist =
    SUMMARIZE (
        FILTER (
            ADDCOLUMNS (
                _summarytable,
                "@condition",
                    COUNTROWS (
                        FILTER (
                            _summarytable,
                            'Users Logins'[Employee ID] = EARLIER ( 'Users Logins'[Employee ID] )
                        )
                    )
            ),
            [@condition] >= 2
        ),
        'Users Logins'[Employee ID]
    )
RETURN
    COUNTROWS ( FILTER ( _monthtable, 'Users Logins'[Employee ID] IN _idlist ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
kl8818
Frequent Visitor

I am still having difficulty working with this solution. It does not represent a correct count in my visual with the formula above. 

A sample visual:

kl8818_1-1703802692181.png

I'd like the highlighted part to be a card visual of the total for those that have logged in the previous month and the month prior to previous month. 

This a measurement I created but I do not know how to adjust it to include those two elements.

Current Month Logins =
CALCULATE(
    DISTINCTCOUNT('User Logins'[Employee ID]),
    MONTH('User Logins'[Logged In Date])=MONTH(TODAY()),
    YEAR('User Logins'[Logged In Date])=YEAR(TODAY())
    )
kl8818
Frequent Visitor

Thanks for sharing this! Is there a way to have that same visual and it show a running count instead of the employee ID? Is that something to adjust in the formula or in the visual?

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1699680652177.png

 

 

Count Expected result measure: = 
VAR _today =
    TODAY ()
VAR _lastmonthenddate =
    EOMONTH ( _today, -1 )
VAR _twomonthsbeforestartdate =
    EOMONTH ( _today, -3 ) + 1
VAR _monthtable =
    FILTER (
        ADDCOLUMNS (
            'Users Logins',
            "@year-month", EOMONTH ( 'Users Logins'[Logged In], 0 )
        ),
        [@year-month] >= _twomonthsbeforestartdate
            && [@year-month] <= _lastmonthenddate
    )
VAR _summarytable =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( _monthtable, [@year-month], 'Users Logins'[Employee ID] ),
            "@logincount", CALCULATE ( COUNTROWS ( 'Users Logins' ) )
        ),
        [@logincount] >= 1
    )
VAR _idlist =
    SUMMARIZE (
        FILTER (
            ADDCOLUMNS (
                _summarytable,
                "@condition",
                    COUNTROWS (
                        FILTER (
                            _summarytable,
                            'Users Logins'[Employee ID] = EARLIER ( 'Users Logins'[Employee ID] )
                        )
                    )
            ),
            [@condition] >= 2
        ),
        'Users Logins'[Employee ID]
    )
RETURN
    COUNTROWS ( FILTER ( _monthtable, 'Users Logins'[Employee ID] IN _idlist ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like or what visualization you want to use to describe the result, but please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_0-1699547459546.png

 

Expected result measure: = 
VAR _today =
    TODAY ()
VAR _lastmonthenddate =
    EOMONTH ( _today, -1 )
VAR _twomonthsbeforestartdate =
    EOMONTH ( _today, -3 ) + 1
VAR _monthtable =
    FILTER (
        ADDCOLUMNS (
            'Users Logins',
            "@year-month", EOMONTH ( 'Users Logins'[Logged In], 0 )
        ),
        [@year-month] >= _twomonthsbeforestartdate
            && [@year-month] <= _lastmonthenddate
    )
VAR _summarytable =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( _monthtable, [@year-month], 'Users Logins'[Employee ID] ),
            "@logincount", CALCULATE ( COUNTROWS ( 'Users Logins' ) )
        ),
        [@logincount] >= 1
    )
RETURN
    SUMMARIZE (
        FILTER (
            ADDCOLUMNS (
                _summarytable,
                "@condition",
                    COUNTROWS (
                        FILTER (
                            _summarytable,
                            'Users Logins'[Employee ID] = EARLIER ( 'Users Logins'[Employee ID] )
                        )
                    )
            ),
            [@condition] >= 2
        ),
        'Users Logins'[Employee ID]
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.