<?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 items in hierarchy in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367975#M126691</link>
    <description>&lt;P&gt;Hey Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This was very helpful from you but the end result should be slightley modified.&lt;BR /&gt;Percentage should be on Item line, not on item variant line.&lt;BR /&gt;If you expand hierarchy it could be both ways - item variant rows could be empty or to replacate value from item line&amp;nbsp;&lt;BR /&gt;&lt;BR /&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;Please advice, thank you!&lt;/P&gt;</description>
    <pubDate>Mon, 07 Aug 2023 08:51:35 GMT</pubDate>
    <dc:creator>pnem</dc:creator>
    <dc:date>2023-08-07T08:51:35Z</dc:date>
    <item>
      <title>Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3365415#M126544</link>
      <description>&lt;P&gt;Hey,&lt;BR /&gt;&lt;BR /&gt;I have issue in counting &lt;STRONG&gt;ItemVariant&lt;/STRONG&gt;&amp;nbsp;for each &lt;STRONG&gt;Item&lt;/STRONG&gt;&amp;nbsp;for &lt;STRONG&gt;Brand&lt;/STRONG&gt; in selected &lt;STRONG&gt;Store&lt;BR /&gt;&lt;/STRONG&gt;So the hierarchie looks like Store/Brand/Item/ItemVariant from top to the bottom&amp;nbsp;&lt;BR /&gt;I need to count first how many ItemVariants are for Item in selected Store&amp;nbsp;&lt;BR /&gt;Then I have stock qty measure to see the stock for Item based on ItemVariant in Store&lt;BR /&gt;So when I count ItemVariants in image example ((6) count) for each Item in that Store I want to see percentage&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;At the end I want to devide count(6) with count of stock quantity where quantity = 0&amp;nbsp;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Result I desire is to have extra column where I will get result for Item in percentage&amp;nbsp;&lt;BR /&gt;Here the result should be - 16.6666667%&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 08:19:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3365415#M126544</guid>
      <dc:creator>pnem</dc:creator>
      <dc:date>2023-08-10T08:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367368#M126650</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="454724" data-lia-user-login="pnem" class="lia-mention lia-mention-user"&gt;pnem&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I created some data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure 2 =
IF(
    ISINSCOPE('Flag'[ItemVariant])&amp;amp;&amp;amp;MAX('Flag'[Value])=0,
    FORMAT(
    DIVIDE(
        COUNTX(
            FILTER(ALL(Flag),            'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])&amp;amp;&amp;amp;'Flag'[Item]=MAX('Flag'[Item])&amp;amp;&amp;amp;'Flag'[Value]=0),[ItemVariant]),
        COUNTX(
            FILTER(ALL(Flag),           'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])&amp;amp;&amp;amp;'Flag'[Item]=MAX('Flag'[Item])),[ItemVariant])),"Percent"),
IF(
    ISINSCOPE('Flag'[ItemVariant]),MAX('Flag'[Value]),
IF(
    ISINSCOPE('Flag'[Item]),
    COUNTX(
            FILTER(ALL(Flag),           'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])&amp;amp;&amp;amp;'Flag'[Item]=MAX('Flag'[Item])),[ItemVariant]),
IF(
    ISINSCOPE('Flag'[Brand]),
     COUNTX(
            FILTER(ALL(Flag),
            'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])),[ItemVariant]),
IF(
    ISINSCOPE('Flag'[Store]),
    COUNTX(
            FILTER(ALL(Flag),
            'Flag'[Store]=MAX('Flag'[Store])),[ItemVariant]),
    COUNTX(ALL(Flag),[Value]))))))&lt;/LI-CODE&gt;
&lt;P&gt;2. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 02:36:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367368#M126650</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-07T02:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367975#M126691</link>
      <description>&lt;P&gt;Hey Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This was very helpful from you but the end result should be slightley modified.&lt;BR /&gt;Percentage should be on Item line, not on item variant line.&lt;BR /&gt;If you expand hierarchy it could be both ways - item variant rows could be empty or to replacate value from item line&amp;nbsp;&lt;BR /&gt;&lt;BR /&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;Please advice, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 08:51:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367975#M126691</guid>
      <dc:creator>pnem</dc:creator>
      <dc:date>2023-08-07T08:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367985#M126692</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="454724" data-lia-user-login="pnem" class="lia-mention lia-mention-user"&gt;pnem&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can modify it to the following dax:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Flag =
IF(
    ISINSCOPE('Flag'[ItemVariant]),MAX('Flag'[Value]),
IF(
    ISINSCOPE('Flag'[Item]),
    FORMAT(
    DIVIDE(
        COUNTX(
            FILTER(ALL(Flag),            'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])&amp;amp;&amp;amp;'Flag'[Item]=MAX('Flag'[Item])&amp;amp;&amp;amp;'Flag'[Value]=0),[ItemVariant]),
        COUNTX(
            FILTER(ALL(Flag),          'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])&amp;amp;&amp;amp;'Flag'[Item]=MAX('Flag'[Item])),[ItemVariant])),"Percent"),
IF(
    ISINSCOPE('Flag'[Brand]),
     COUNTX(
            FILTER(ALL(Flag),
            'Flag'[Store]=MAX('Flag'[Store])&amp;amp;&amp;amp;'Flag'[Brand]=MAX('Flag'[Brand])),[ItemVariant]),
IF(
    ISINSCOPE('Flag'[Store]),
    COUNTX(
            FILTER(ALL(Flag),
            'Flag'[Store]=MAX('Flag'[Store])),[ItemVariant]),
    COUNTX(ALL(Flag),[Value])))))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 09:01:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3367985#M126692</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-07T09:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3370056#M126800</link>
      <description>&lt;P&gt;hey&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have created measure which return count for each scope in "&lt;SPAN&gt;hierarchy&lt;/SPAN&gt;"&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Measure 5 = 
SWITCH(true(),
ISINSCOPE(DimItem[Item Code]),[MeasureITEMVARIANTID],
ISINSCOPE(DimItem[Brand]),[MeasureITEMID],
ISINSCOPE(DimLocation[Location Name]),[MeasureBRANDID]) 


MeasureITEMVARIANTID
MeasureITEMID
MeasureBRANDID 

are distinccount() for each column &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now I want to count how many 0 are in each scope&lt;BR /&gt;&lt;BR /&gt;Eg. for this item in example i want to have for each 0 null and above number 4&amp;nbsp; - first level of hierachy&amp;nbsp;&lt;BR /&gt;than if we collapse item to brand same thing - just to count 0 for each scope&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;hope I was clear&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Please advice, thanks!&lt;BR /&gt;&lt;BR /&gt;Regards Nem&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 10:30:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3370056#M126800</guid>
      <dc:creator>pnem</dc:creator>
      <dc:date>2023-08-08T10:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3373695#M126997</link>
      <description>&lt;P&gt;Still facing the issue, any advice?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 08:17:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3373695#M126997</guid>
      <dc:creator>pnem</dc:creator>
      <dc:date>2023-08-10T08:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3380320#M127344</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="454724" data-lia-user-login="pnem" class="lia-mention lia-mention-user"&gt;pnem&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, can you present the expected result in the form of a picture, because the data I created with you and I will be different, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 08:38:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3380320#M127344</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-15T08:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3380356#M127346</link>
      <description>&lt;P&gt;hey&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;as I already posted -&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&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;Measure 5 = 
SWITCH(true(),
ISINSCOPE(DimItem[Item Code]),[MeasureITEMVARIANTID],
ISINSCOPE(DimItem[Brand]),[MeasureITEMID],
ISINSCOPE(DimLocation[Location Name]),[MeasureBRANDID]) 


MeasureITEMVARIANTID
MeasureITEMID
MeasureBRANDID 

are distinccount() for each column &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So this value is retriving number of subcategory for each scope.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have measure [stock qty] and I want for each category to have some kind of a filter where [stock qty] = 0&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;want to sum all subcategories where [stock qty] = 0&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Eg -&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;variantQty is measure 5 and I want to create &lt;STRONG&gt;failedVariant&lt;/STRONG&gt; measure for each level of "hierachy"&amp;nbsp;&lt;BR /&gt;Then I will calculate further in report like&amp;nbsp;&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;divide(failedVariant/measure5)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Want to point out that I am using model (SSAS) and I am not able to create calculated columns...&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Hope you can understand now better the issue.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 09:14:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3380356#M127346</guid>
      <dc:creator>pnem</dc:creator>
      <dc:date>2023-08-15T09:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count items in hierarchy</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3396663#M128138</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="454724" data-lia-user-login="pnem" class="lia-mention lia-mention-user"&gt;pnem&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;failedVariant =
var _select=SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])&amp;amp;&amp;amp;'Table'[name]=MAX('Table'[name])&amp;amp;&amp;amp;'Table'[brand]=MAX('Table'[brand])),"itemgroup",[StockQty])
return
IF(
    [StockQty] = 0 &amp;amp;&amp;amp; HASONEVALUE('Table'[item]) ,1,
    IF(
        [StockQty] &amp;lt;&amp;gt; 0&amp;amp;&amp;amp; HASONEVALUE('Table'[item]) ,0,
    IF(
         0 in _select &amp;amp;&amp;amp; HASONEVALUE('Table'[brand]),COUNTX(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])&amp;amp;&amp;amp;'Table'[name]=MAX('Table'[name])&amp;amp;&amp;amp;'Table'[brand]=MAX('Table'[brand])&amp;amp;&amp;amp;[StockQty]=0),[item]),
         IF(
             HASONEVALUE('Table'[name]),         COUNTX(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])&amp;amp;&amp;amp;'Table'[name]=MAX('Table'[name])),[item]),
             IF(              HASONEVALUE('Table'[loc1]),COUNTX(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])),[item]),0)))))
divide =
DIVIDE(
    [failedVariant],[StockQty])&lt;/LI-CODE&gt;
&lt;P&gt;2. Result:&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;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2023 09:35:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-items-in-hierarchy/m-p/3396663#M128138</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-24T09:35:56Z</dc:date>
    </item>
  </channel>
</rss>

