<?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: Help with DAX Measures on Parent Child tables recursively in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3490471#M133630</link>
    <description>&lt;P&gt;To create DAX measures that count the number of Automate, Manual, and Unique Activities by recursively traversing the parent-child hierarchy in your Pipelines table, you can use DAX functions like SUMX, FILTER, and recursion with a custom DAX function. Here's a step-by-step guide on how to achieve this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 1: Create a DAX Function for Recursive Calculation&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;First, you need to create a custom DAX function that can recursively traverse the parent-child hierarchy in your Pipelines table. You can do this by using a recursive CTE (Common Table Expression) in Power Query. Here's a simplified example of such a function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RecursivePipelineActivities =&lt;BR /&gt;VAR Recurse =&lt;BR /&gt;ADDCOLUMNS (&lt;BR /&gt;Pipelines,&lt;BR /&gt;"ActivitiesCount",&lt;BR /&gt;COUNTROWS (&lt;BR /&gt;FILTER (&lt;BR /&gt;Activities,&lt;BR /&gt;RELATED ( Activities[PipelineId] ) = Pipelines[PipelineId]&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;VAR Result =&lt;BR /&gt;SUMX ( Recurse, [ActivitiesCount] )&lt;BR /&gt;RETURN&lt;BR /&gt;Result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This function, RecursivePipelineActivities, will calculate the sum of activities for the given pipeline and all its children.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 2: Create Measures&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Now, you can create measures based on the custom function. Here's how you can create the measures you mentioned:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;# of Automate&lt;/STRONG&gt;:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;# of Automate =&lt;BR /&gt;VAR TypeToCount = "A"&lt;BR /&gt;VAR PipelinesWithAutomate =&lt;BR /&gt;FILTER ( Pipelines, Pipelines[PipelineType] = TypeToCount )&lt;BR /&gt;RETURN&lt;BR /&gt;[RecursivePipelineActivities]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# of Manual&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;# of Manual =&lt;BR /&gt;VAR TypeToCount = "M"&lt;BR /&gt;VAR PipelinesWithManual =&lt;BR /&gt;FILTER ( Pipelines, Pipelines[PipelineType] = TypeToCount )&lt;BR /&gt;RETURN&lt;BR /&gt;[RecursivePipelineActivities]&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;# of Unique Activities&lt;/STRONG&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;# of Unique Activities =&lt;BR /&gt;VAR DistinctActivities =&lt;BR /&gt;SUMMARIZE ( Activities, Activities[ActivityId] )&lt;BR /&gt;RETURN&lt;BR /&gt;COUNTROWS ( DistinctActivities )&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These measures use the RecursivePipelineActivities function to calculate the counts of activities for the specified pipeline types and then count unique activities for the third measure.&lt;/P&gt;&lt;P&gt;Make sure you adjust the TypeToCount variable to match the specific types you want to count.&lt;/P&gt;&lt;P&gt;This approach assumes you have created relationships between the Pipelines and Activities tables as you described in your question. Also, please note that the provided DAX code is a simplified example, and you may need to adapt it to your specific data model and requirements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2023 06:13:09 GMT</pubDate>
    <dc:creator>123abc</dc:creator>
    <dc:date>2023-10-23T06:13:09Z</dc:date>
    <item>
      <title>Help with DAX Measures on Parent Child tables recursively</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3490199#M133596</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables, Pipelines and Activities. Pipeline Table has ParentPipelineId's, I want to create below measures by travelling recursively at the root level. I have created basic measurse but need help on recursive part. Please help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Measues:&lt;/P&gt;&lt;P&gt;# of Automate ==&amp;gt;&lt;/P&gt;&lt;P&gt;Example: For PipelineType ==&amp;gt; A =&amp;gt; We want to travel till root (child) and consider count all the activities, in this case it should Activities For 123 (3) + Activities for 456 (2) + Activities for 789 (2)&lt;/P&gt;&lt;P&gt;# of Manual ==&amp;gt; Same Behaviour as Automate by TaskType will be Manual&lt;/P&gt;&lt;P&gt;# of Unique Activities =&amp;gt; We want to travel till root and consider distinct Activity ID&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example: For Pipeline TypA, Activity ID 1 is repeating in both PipelineId 123 and 789, we want to count as 1.&lt;/P&gt;&lt;P&gt;Relationship:&lt;/P&gt;&lt;P&gt;Pipelines ( PipelineId - 1) &amp;lt;-------- Activities ( PipelineId --*)&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;Thanks,&lt;/P&gt;&lt;P&gt;Abhiram&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 02:29:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3490199#M133596</guid>
      <dc:creator>abhiram342</dc:creator>
      <dc:date>2023-10-23T02:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DAX Measures on Parent Child tables recursively</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3490471#M133630</link>
      <description>&lt;P&gt;To create DAX measures that count the number of Automate, Manual, and Unique Activities by recursively traversing the parent-child hierarchy in your Pipelines table, you can use DAX functions like SUMX, FILTER, and recursion with a custom DAX function. Here's a step-by-step guide on how to achieve this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 1: Create a DAX Function for Recursive Calculation&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;First, you need to create a custom DAX function that can recursively traverse the parent-child hierarchy in your Pipelines table. You can do this by using a recursive CTE (Common Table Expression) in Power Query. Here's a simplified example of such a function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RecursivePipelineActivities =&lt;BR /&gt;VAR Recurse =&lt;BR /&gt;ADDCOLUMNS (&lt;BR /&gt;Pipelines,&lt;BR /&gt;"ActivitiesCount",&lt;BR /&gt;COUNTROWS (&lt;BR /&gt;FILTER (&lt;BR /&gt;Activities,&lt;BR /&gt;RELATED ( Activities[PipelineId] ) = Pipelines[PipelineId]&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;VAR Result =&lt;BR /&gt;SUMX ( Recurse, [ActivitiesCount] )&lt;BR /&gt;RETURN&lt;BR /&gt;Result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This function, RecursivePipelineActivities, will calculate the sum of activities for the given pipeline and all its children.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 2: Create Measures&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Now, you can create measures based on the custom function. Here's how you can create the measures you mentioned:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;# of Automate&lt;/STRONG&gt;:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;# of Automate =&lt;BR /&gt;VAR TypeToCount = "A"&lt;BR /&gt;VAR PipelinesWithAutomate =&lt;BR /&gt;FILTER ( Pipelines, Pipelines[PipelineType] = TypeToCount )&lt;BR /&gt;RETURN&lt;BR /&gt;[RecursivePipelineActivities]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# of Manual&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;# of Manual =&lt;BR /&gt;VAR TypeToCount = "M"&lt;BR /&gt;VAR PipelinesWithManual =&lt;BR /&gt;FILTER ( Pipelines, Pipelines[PipelineType] = TypeToCount )&lt;BR /&gt;RETURN&lt;BR /&gt;[RecursivePipelineActivities]&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;# of Unique Activities&lt;/STRONG&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;# of Unique Activities =&lt;BR /&gt;VAR DistinctActivities =&lt;BR /&gt;SUMMARIZE ( Activities, Activities[ActivityId] )&lt;BR /&gt;RETURN&lt;BR /&gt;COUNTROWS ( DistinctActivities )&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These measures use the RecursivePipelineActivities function to calculate the counts of activities for the specified pipeline types and then count unique activities for the third measure.&lt;/P&gt;&lt;P&gt;Make sure you adjust the TypeToCount variable to match the specific types you want to count.&lt;/P&gt;&lt;P&gt;This approach assumes you have created relationships between the Pipelines and Activities tables as you described in your question. Also, please note that the provided DAX code is a simplified example, and you may need to adapt it to your specific data model and requirements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 06:13:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3490471#M133630</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2023-10-23T06:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DAX Measures on Parent Child tables recursively</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3492619#M133752</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="403667" data-lia-user-login="123abc" class="lia-mention lia-mention-user"&gt;123abc&lt;/a&gt;&amp;nbsp; &amp;nbsp;- Thank you for your response. I wwas facing issuing while creating function. Can you please tell what's input for function? I copied function code in measure but it's complainig about relationship, I have valid relationship between table. Also, For # of Automate, I don't want to harcode PipelineType, I assume It's TaskType = "Automate" . I tried to create measure in Activity table but it has same error.&lt;/P&gt;&lt;P&gt;Please find screenshot below&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Abhiram&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 01:28:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DAX-Measures-on-Parent-Child-tables-recursively/m-p/3492619#M133752</guid>
      <dc:creator>abhiram342</dc:creator>
      <dc:date>2023-10-24T01:28:12Z</dc:date>
    </item>
  </channel>
</rss>

