<?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: Counting players that are part of a party that haven't done an action recently (or ever) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3092740#M108396</link>
    <description>&lt;P&gt;As a follow-up: my queries seemed slow, so I looked at them using DAX studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found out Power BI was iterating over the full Action_Occurrences table, which has more than 100k rows in my dataset, so I changed the measure to (1) filter earlier and (2) avoid adding columns to that table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The resulting query is a little more complex but consistently works 5 times faster with my data (from 2.5 seconds to 0.5 seconds to evaluate it) and yields the same results:&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;Treasureless Wizards = CALCULATE(
    COUNTROWS(
        // Variable table for invalid action occurrences (those we don't want)
        // All the "find treasure" actions that happened in the past 10 days
        VAR _Unwanted = SELECTCOLUMNS(
            CALCULATETABLE(
                FILTER(
                    'Action_Occurrences',
                    DATEDIFF('Action_Occurrences'[Date], UTCTODAY(), DAY) &amp;lt;= 10
                ),
                'Action_Types'[Action Description] = "Find a treasure"
            ),
            "Party",
            RELATED('Party_Actions'[Party ID])
        )
        // Use NOT to remove the players that are in a party that does not fill the conditions
        RETURN FILTER('Players', NOT('Players'[Party ID] in _Unwanted))
    ),
    // Players that are wizards and that have a party
    Player_Families[Family] = "Wizard",
    KEEPFILTERS(NOT(ISBLANK('Players'[Party ID])))
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2023 11:24:19 GMT</pubDate>
    <dc:creator>leste</dc:creator>
    <dc:date>2023-02-22T11:24:19Z</dc:date>
    <item>
      <title>Counting players that are part of a party that haven't done an action recently (or ever)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3083772#M107642</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to Power BI and I want to try to make a measure based on the following model:&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to find is the count of players, that are wizards, that are in a party, and whose party didn't perform a given action (for instance "Find a treasure") recently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A player should never be counted in these cases:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If the player is not in the "Wizard" family, then it's not a match&lt;/LI&gt;&lt;LI&gt;If the player does not belong to a party, then it's not a match&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;If a player is a wizard that belongs to a party, it should only be counted in these cases:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If the "Find a treasure" action is missing from the "Party_Actions" table, then the party has never performed the action, so it's a match&lt;/LI&gt;&lt;LI&gt;If the "Find a treasure" action is there, but there are no occurrences, then the party has never performed the action, so it's a match&lt;/LI&gt;&lt;LI&gt;If the action is there, but all occurrences happened more than 10 days ago, then it's a match&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So far I've come up with the following DAX measure:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;Players in that situation =
CALCULATE(
    CALCULATE(
        COUNTROWS(Players),
        // Action is "Find a treasure"
        KEEPFILTERS(Action_Types[Action Description] = "Find a treasure"),
        // There has been no action in the past 10 days
        COUNTROWS(
            FILTER('Action_Occurrences', DATEDIFF([Date], UTCTODAY(), DAY) &amp;gt;= 10)
        ) &amp;gt; 0
    ),
    // Players that are wizards
    KEEPFILTERS(Player_Families[Family] = "Wizard"),
    // And belong to a party
    NOT(ISBLANK(Players[Party ID])
))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it doesn't work (I get errors), and I think that even if I could get it to work, it wouldn't match the cases I want (especially when the action doesn't exist, or when the action has no occurrences; in these cases, I want to count the player, but here I think it will ski&lt;/P&gt;&lt;P&gt;p the players).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you have any leads?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 17:28:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3083772#M107642</guid>
      <dc:creator>leste</dc:creator>
      <dc:date>2023-02-16T17:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting players that are part of a party that haven't done an action recently (or ever)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3084013#M107661</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="516129" data-lia-user-login="leste" class="lia-mention lia-mention-user"&gt;leste&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;This was quite fun issue to ponder. Here is one way to go about this:&lt;BR /&gt;&lt;BR /&gt;1. I drew a flowchart to help me visualize the challenge:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Based on this I created the following dax:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Player Count = 

COUNTROWS(
     var _table = FILTER(ADDCOLUMNS(Action_occurrance,"Type", RELATED(Action_types[Description]),"Party",RELATED(Actions[PartyID])),and([Type]="Find Treasure",[Date]&amp;gt;=TODAY()-10)) return // variable table for invalid action occurances


FILTER(
    ADDCOLUMNS(
    Players,"Family",RELATED(Player_family[Family]), "Party", RELATED(Parties[PartyId])), 
    [Family]="Wizard" &amp;amp;&amp;amp; not(ISBLANK([Party])) //Filter for wizards who have a party
    &amp;amp;&amp;amp; not([Party]  in {
 SELECTCOLUMNS(_table,"Party",[Party])})
 //Parties who don't fill the conditions = have found treasure in 10 days. I am using Not in to remove the players who are in these parties from count
)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!&lt;BR /&gt;&lt;BR /&gt;My LinkedIn: &lt;A href="https://www.linkedin.com/in/n%C3%A4ttiahov-00001/" target="_blank" rel="noopener"&gt;https://www.linkedin.com/in/n%C3%A4ttiahov-00001/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 20:52:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3084013#M107661</guid>
      <dc:creator>ValtteriN</dc:creator>
      <dc:date>2023-02-16T20:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting players that are part of a party that haven't done an action recently (or ever)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3085389#M107803</link>
      <description>&lt;P&gt;Wow, that's quite a formula!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works like a charm, I just had to remove the curly braces { } around SELECTCOLUMNS. I also wrapped everything in a CALCULATE function, so that I could move one of the filters (not(ISBLANK([Party])) to that level (I've read it's a good practice so that filters are applied early).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The numbers seem to match the data I throw at the measure, so I think it's good! Thank you a thousand times!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I now know how many wizards haven't found treasures recently, maybe they need a little magic help too 🧙&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 16:29:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3085389#M107803</guid>
      <dc:creator>leste</dc:creator>
      <dc:date>2023-02-17T16:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting players that are part of a party that haven't done an action recently (or ever)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3092740#M108396</link>
      <description>&lt;P&gt;As a follow-up: my queries seemed slow, so I looked at them using DAX studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found out Power BI was iterating over the full Action_Occurrences table, which has more than 100k rows in my dataset, so I changed the measure to (1) filter earlier and (2) avoid adding columns to that table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The resulting query is a little more complex but consistently works 5 times faster with my data (from 2.5 seconds to 0.5 seconds to evaluate it) and yields the same results:&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;Treasureless Wizards = CALCULATE(
    COUNTROWS(
        // Variable table for invalid action occurrences (those we don't want)
        // All the "find treasure" actions that happened in the past 10 days
        VAR _Unwanted = SELECTCOLUMNS(
            CALCULATETABLE(
                FILTER(
                    'Action_Occurrences',
                    DATEDIFF('Action_Occurrences'[Date], UTCTODAY(), DAY) &amp;lt;= 10
                ),
                'Action_Types'[Action Description] = "Find a treasure"
            ),
            "Party",
            RELATED('Party_Actions'[Party ID])
        )
        // Use NOT to remove the players that are in a party that does not fill the conditions
        RETURN FILTER('Players', NOT('Players'[Party ID] in _Unwanted))
    ),
    // Players that are wizards and that have a party
    Player_Families[Family] = "Wizard",
    KEEPFILTERS(NOT(ISBLANK('Players'[Party ID])))
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 11:24:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-players-that-are-part-of-a-party-that-haven-t-done-an/m-p/3092740#M108396</guid>
      <dc:creator>leste</dc:creator>
      <dc:date>2023-02-22T11:24:19Z</dc:date>
    </item>
  </channel>
</rss>

