<?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 Write Dax query to create a agent buckets based on 2 different relationship in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Write-Dax-query-to-create-a-agent-buckets-based-on-2-different/m-p/4377727#M173804</link>
    <description>&lt;P&gt;Hi Team ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write a Dax query to&amp;nbsp; create a agent buckets based on 2 different relationship for example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table A:&lt;/P&gt;&lt;P&gt;Key_Agent_MonthYear&lt;/P&gt;&lt;P&gt;Agent&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sales&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table B&lt;/P&gt;&lt;P&gt;Agent bucket&amp;nbsp;&lt;/P&gt;&lt;P&gt;Agent&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key_Agent_MonthYear&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;i need to create bucket based on 2 scenario for first 2 measures need to consider all agents till date like&amp;nbsp; if month is Jun 24 then bucket should be based on all cummulative agents .&lt;/LI&gt;&lt;LI&gt;but for Active Fc we need to create bucket based on monthly agents like&amp;nbsp; if filter is Jun 24 then agent bucket should be based on Jun 24 agent records .&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Agent Bucket&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;Total agent&lt;/TD&gt;&lt;TD&gt;Active agent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AB&lt;/TD&gt;&lt;TD&gt;for this Dax query should give records based on Table A[Agent] and Table B[Agent ]&lt;/TD&gt;&lt;TD&gt;for this Dax query should give records based on Table A[Agent] and Table B[Agent ]&lt;/TD&gt;&lt;TD&gt;for this Dax query should give records based on Table A[Key_Agent_MonthYear] and Table B[Key_Agent_MonthYear ]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;QC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SQC+&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;i tried 1 active and 1 non active relation but it is slow and if i use User relationship it gives error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I tried Treatas and Intersect function as well but it is very slow .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to PBI , pls let me know if any solution in Dax side or Power query side .&lt;/P&gt;&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="118660" data-lia-user-login="rajendraongole1" class="lia-mention lia-mention-user"&gt;rajendraongole1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Dilip&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2025 12:36:14 GMT</pubDate>
    <dc:creator>Dilip7</dc:creator>
    <dc:date>2025-01-23T12:36:14Z</dc:date>
    <item>
      <title>Write Dax query to create a agent buckets based on 2 different relationship</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Write-Dax-query-to-create-a-agent-buckets-based-on-2-different/m-p/4377727#M173804</link>
      <description>&lt;P&gt;Hi Team ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write a Dax query to&amp;nbsp; create a agent buckets based on 2 different relationship for example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table A:&lt;/P&gt;&lt;P&gt;Key_Agent_MonthYear&lt;/P&gt;&lt;P&gt;Agent&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sales&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table B&lt;/P&gt;&lt;P&gt;Agent bucket&amp;nbsp;&lt;/P&gt;&lt;P&gt;Agent&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key_Agent_MonthYear&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;i need to create bucket based on 2 scenario for first 2 measures need to consider all agents till date like&amp;nbsp; if month is Jun 24 then bucket should be based on all cummulative agents .&lt;/LI&gt;&lt;LI&gt;but for Active Fc we need to create bucket based on monthly agents like&amp;nbsp; if filter is Jun 24 then agent bucket should be based on Jun 24 agent records .&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Agent Bucket&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;Total agent&lt;/TD&gt;&lt;TD&gt;Active agent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AB&lt;/TD&gt;&lt;TD&gt;for this Dax query should give records based on Table A[Agent] and Table B[Agent ]&lt;/TD&gt;&lt;TD&gt;for this Dax query should give records based on Table A[Agent] and Table B[Agent ]&lt;/TD&gt;&lt;TD&gt;for this Dax query should give records based on Table A[Key_Agent_MonthYear] and Table B[Key_Agent_MonthYear ]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;QC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SQC+&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;i tried 1 active and 1 non active relation but it is slow and if i use User relationship it gives error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I tried Treatas and Intersect function as well but it is very slow .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to PBI , pls let me know if any solution in Dax side or Power query side .&lt;/P&gt;&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="118660" data-lia-user-login="rajendraongole1" class="lia-mention lia-mention-user"&gt;rajendraongole1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Dilip&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 12:36:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Write-Dax-query-to-create-a-agent-buckets-based-on-2-different/m-p/4377727#M173804</guid>
      <dc:creator>Dilip7</dc:creator>
      <dc:date>2025-01-23T12:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Write Dax query to create a agent buckets based on 2 different relationship</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Write-Dax-query-to-create-a-agent-buckets-based-on-2-different/m-p/4377770#M173806</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="759967" data-lia-user-login="Dilip7" class="lia-mention lia-mention-user"&gt;Dilip7&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;The error indicates that you are encountering a problem with overlapping relationships in your data model, leading to ambiguity in Power BI.&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color="#000000"&gt;Check the Model relationship&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;Two Relationships Issue: It seems you have two paths (relationships) connecting your tables ( Table A and Table B ) to the same key columns. This causes Power BI to throw a tree-formation error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ensure you use only one active relationship between the tables while setting the second relationship as inactive. Use DAX to activate the inactive relationship dynamically where needed.&lt;/P&gt;
&lt;P&gt;you need two types of DAX measures, one for cumulative agents (using the active relationship) and One for monthly agents (activating the inactive relationship dynamically).&lt;/P&gt;
&lt;P&gt;To calculate the cumulative agent bucket based on all agents till the selected date:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;CumulativeAgents =
CALCULATE(
    COUNTROWS('Table B'),
    FILTER(
        ALL('Table B'[Key_Agent_MonthYear]),
        'Table B'[Key_Agent_MonthYear] &amp;lt;= MAX('Table A'[Key_Agent_MonthYear])
    )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To calculate agent buckets for a specific month, use the USERRELATIONSHIP function to leverage the inactive relationship:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;MonthlyAgents =
CALCULATE(
    COUNTROWS('Table B'),
    USERELATIONSHIP('Table A'[Key_Agent_MonthYear], 'Table B'[Key_Agent_MonthYear])
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H5&gt;&amp;nbsp;&lt;/H5&gt;
&lt;P&gt;To group by agent bucket:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;SalesByBucket =
SUMMARIZE(
    'Table B',
    'Table B'[Agent Bucket],
    "Total Sales", SUM('Table A'[Sales]),
    "Cumulative Agents", [CumulativeAgents],
    "Active Agents", [MonthlyAgents]
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H4&gt;&amp;nbsp;&lt;/H4&gt;
&lt;P&gt;If you experience slowness:&lt;/P&gt;
&lt;P&gt;Ensure your data model is optimized, with fewer calculated columns and a star schema structure.&lt;/P&gt;
&lt;P&gt;Pre-aggregate or calculate buckets in &lt;STRONG&gt;Power Query if the dataset size is manageable.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please mark this as solution if it helps you. Appreciate Kudos&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 12:56:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Write-Dax-query-to-create-a-agent-buckets-based-on-2-different/m-p/4377770#M173806</guid>
      <dc:creator>FarhanJeelani</dc:creator>
      <dc:date>2025-01-23T12:56:42Z</dc:date>
    </item>
  </channel>
</rss>

