<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Count of users performing specific action in specified period in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459010#M66454</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;The measure, and the validation of the measure are in the attached pbix file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Perform Action1 in the last two months measure: = 
VAR latestmonthenddate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), 0 )
VAR latestmonthstartdate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), -1 ) + 1
VAR secondlatestmonthstartdate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), -2 ) + 1
VAR secondlatestmonthenddate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), -1 )
VAR oneactivityperuserpermonth =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( UserActivity, UserActivity[UserID], UserActivity[TimeFrame] ),
            "@activitycount", CALCULATE ( COUNTROWS ( VALUES ( UserActivity[ProductActivity] ) ) ),
            "@productactivity", CALCULATE ( SELECTEDVALUE ( UserActivity[ProductActivity] ) )
        ),
        [@activitycount] = 1
            &amp;amp;&amp;amp; [@productactivity] = "Action1"
    )
VAR latestmonthaction1 =
    SUMMARIZE (
        FILTER (
            oneactivityperuserpermonth,
            UserActivity[TimeFrame] &amp;gt;= latestmonthstartdate
                &amp;amp;&amp;amp; UserActivity[TimeFrame] &amp;lt;= latestmonthenddate
        ),
        UserActivity[UserID]
    )
VAR secondlatestmonthaction1 =
    SUMMARIZE (
        FILTER (
            oneactivityperuserpermonth,
            UserActivity[TimeFrame] &amp;gt;= secondlatestmonthstartdate
                &amp;amp;&amp;amp; UserActivity[TimeFrame] &amp;lt;= secondlatestmonthstartdate
        ),
        UserActivity[UserID]
    )
RETURN
    COUNTROWS ( INTERSECT ( latestmonthaction1, secondlatestmonthaction1 ) )
&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 15 Apr 2022 11:04:32 GMT</pubDate>
    <dc:creator>Jihwan_Kim</dc:creator>
    <dc:date>2022-04-15T11:04:32Z</dc:date>
    <item>
      <title>Count of users performing specific action in specified period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2458976#M66450</link>
      <description>&lt;P&gt;Hello, I'm fairly new to Power BI and DAX, and I've been stuck on this problem for a few days now.&amp;nbsp;&lt;BR /&gt;I'm looking to count the number of users who have only performed a specific action in the last few months.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a simplified example of the table.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;UserID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;TimeFrame&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;ProductActivity&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;March 2022&lt;/TD&gt;&lt;TD&gt;Action1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;February 2022&lt;/TD&gt;&lt;TD&gt;Action2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;January 2022&lt;/TD&gt;&lt;TD&gt;Action2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;March 2022&lt;/TD&gt;&lt;TD&gt;Action1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;February 2022&lt;/TD&gt;&lt;TD&gt;Action1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;January 2022&lt;/TD&gt;&lt;TD&gt;Action2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;March 2022&lt;/TD&gt;&lt;TD&gt;Action1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;February 2022&lt;/TD&gt;&lt;TD&gt;Action1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;January 2022&lt;/TD&gt;&lt;TD&gt;Action3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;March 2022&lt;/TD&gt;&lt;TD&gt;Action2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;February 2022&lt;/TD&gt;&lt;TD&gt;Action2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;January 2022&lt;/TD&gt;&lt;TD&gt;Action2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say I'm looking for the count of users who only performed Action1 in the last two months (March and February),&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example, a count of 2 should be returned because users 2 &amp;amp; 3 only performed Action1 in March and February.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is where I'm at in my code.&lt;/P&gt;&lt;P&gt;I start by counting the number of distinct activities performed in the specified period, and returning True if the count is equal to one.&lt;/P&gt;&lt;P&gt;When grouped by UserID, this should indicate which users only performed a unique action for the specified month.&lt;/P&gt;&lt;P&gt;Next, I perform an if statement to check if the rows equal to true have a [ProductActivity] = activity. The goal here is to only mark rows as True if the only action performed is the action in desired. Unfortunately, this is where my code falls apart and I get an error "A single value for column 'ProductActivity' cannot be determined". I think I understand why this error is occuring, but I have no idea how to resolve it.&lt;/P&gt;&lt;P&gt;Finally, I planned on doing a count of all True values from the previous step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;User Count = 
    var months = 2
    var activity = "Action1"

    // For each user, return True if they have only performed one activity during the specified period
    // Ex: If User 1 performed Action 1 in January and Action 2 in February, return False. 
    // If they performed only Action 1 in both January and February, return True.
    var verify_single_activity = CALCULATE
    (
        // Count number of unique activities 
        DISTINCTCOUNT('UserActivity'[ProductActivity]),
     
        // Only check specified last few months
        DATESBETWEEN
        (
            'UserActivity'[TimeFrame], 
            EDATE(TODAY(), - months), 
            TODAY()
        )
    ) = 1
    
    // If a user has performed only one action, verify that the activity is the one we are specifically targetting
    var verify_appropriate_activity = IF
    (
        verify_single_activity = True,
        IF
        (
            'UserActivity'[ProductActivity] = activity,
            True,
            False
        ),
        False
    )

    return verify_appropriate_activity&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for taking the time to read this. I'm hoping someone could help me figure out what I'm missing, or perhaps offer a solution that is way more simple. I feel like this would be a piece of cake to do in SQL, but I'm still figuring out how DAX works.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2022 10:35:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2458976#M66450</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-15T10:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count of users performing specific action in specified period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459010#M66454</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;The measure, and the validation of the measure are in the attached pbix file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Perform Action1 in the last two months measure: = 
VAR latestmonthenddate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), 0 )
VAR latestmonthstartdate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), -1 ) + 1
VAR secondlatestmonthstartdate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), -2 ) + 1
VAR secondlatestmonthenddate =
    EOMONTH ( MAX ( UserActivity[TimeFrame] ), -1 )
VAR oneactivityperuserpermonth =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( UserActivity, UserActivity[UserID], UserActivity[TimeFrame] ),
            "@activitycount", CALCULATE ( COUNTROWS ( VALUES ( UserActivity[ProductActivity] ) ) ),
            "@productactivity", CALCULATE ( SELECTEDVALUE ( UserActivity[ProductActivity] ) )
        ),
        [@activitycount] = 1
            &amp;amp;&amp;amp; [@productactivity] = "Action1"
    )
VAR latestmonthaction1 =
    SUMMARIZE (
        FILTER (
            oneactivityperuserpermonth,
            UserActivity[TimeFrame] &amp;gt;= latestmonthstartdate
                &amp;amp;&amp;amp; UserActivity[TimeFrame] &amp;lt;= latestmonthenddate
        ),
        UserActivity[UserID]
    )
VAR secondlatestmonthaction1 =
    SUMMARIZE (
        FILTER (
            oneactivityperuserpermonth,
            UserActivity[TimeFrame] &amp;gt;= secondlatestmonthstartdate
                &amp;amp;&amp;amp; UserActivity[TimeFrame] &amp;lt;= secondlatestmonthstartdate
        ),
        UserActivity[UserID]
    )
RETURN
    COUNTROWS ( INTERSECT ( latestmonthaction1, secondlatestmonthaction1 ) )
&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 15 Apr 2022 11:04:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459010#M66454</guid>
      <dc:creator>Jihwan_Kim</dc:creator>
      <dc:date>2022-04-15T11:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Count of users performing specific action in specified period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459016#M66455</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;You may try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;User Count =
VAR Activity = "Action1"
VAR Months = 2
VAR CurrentPeriod =
    TODAY ()
VAR LastPeriod =
    EDATE ( TODAY (), - Months )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'UserActivity'[ProductActivity] ),
        'UserActivity'[TimeFrame] &amp;gt;= LastPeriod,
        CurrentPeriod,
        'UserActivity'[Activity] = Activity
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 15 Apr 2022 11:18:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459016#M66455</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-04-15T11:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count of users performing specific action in specified period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459288#M66477</link>
      <description>&lt;P&gt;Thanks a lot for your very thorough answer. I sincrerely appreciate it.&lt;BR /&gt;Your solution isn't exactly what I was looking for, but it definitely helped me find the proper solution.&lt;/P&gt;&lt;P&gt;Here is the solution I found:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var activity = "Action1"
var months = 2

// Evaluate only the rows with a TimeFrame between now and 'months' months ago.
var date_range = 
DATESBETWEEN (
    UserActivity[TimeFrame], 
    EDATE(TODAY(), - months), 
    TODAY()
)
    
// Create a new table with two only two columns, UserID and @product_activity
var new_table = 
FILTER (
    ADDCOLUMNS (
        SUMMARIZE ( UserActivity, UserActivity[UserID] ),
        // For each UserID in the specified date_range, if there is only one unique value in ProductActivity, return the value
        "@product_activity", CALCULATE ( 
            SELECTEDVALUE ( UserActivity[ProductActivity] ) ,
            date_range
        )
    ),
    // Only add row to the new table if the activity is the one we are looking for
    [@product_activity] = activity
)

return CALCULATE( COUNTROWS(new_table) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2022 16:29:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459288#M66477</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-15T16:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count of users performing specific action in specified period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459294#M66478</link>
      <description>&lt;P&gt;Thanks for your reply. This is actually what I did intially, but this counts only users who have performed the action at least once within the date range. I was looking for all the users who have exclusively performed the action within the date range.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2022 16:33:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-of-users-performing-specific-action-in-specified-period/m-p/2459294#M66478</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-15T16:33:08Z</dc:date>
    </item>
  </channel>
</rss>

