Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Dilip7
Frequent Visitor

Write Dax query to create a agent buckets based on 2 different relationship

Hi Team ,

 

I want to write a Dax query to  create a agent buckets based on 2 different relationship for example 

 

Table A:

Key_Agent_MonthYear

Agent 

Sales 

 

Table B

Agent bucket 

Agent 

Key_Agent_MonthYear

 

Output:

  • i need to create bucket based on 2 scenario for first 2 measures need to consider all agents till date like  if month is Jun 24 then bucket should be based on all cummulative agents .
  • but for Active Fc we need to create bucket based on monthly agents like  if filter is Jun 24 then agent bucket should be based on Jun 24 agent records .

 

Agent BucketSalesTotal agentActive agent
ABfor this Dax query should give records based on Table A[Agent] and Table B[Agent ]for this Dax query should give records based on Table A[Agent] and Table B[Agent ]for this Dax query should give records based on Table A[Key_Agent_MonthYear] and Table B[Key_Agent_MonthYear ]
SG
QC
SQC+

i tried 1 active and 1 non active relation but it is slow and if i use User relationship it gives error 

Dilip7_0-1737635609895.png

I tried Treatas and Intersect function as well but it is very slow .

 

I am new to PBI , pls let me know if any solution in Dax side or Power query side .

@rajendraongole1 

-Dilip

1 ACCEPTED SOLUTION
FarhanJeelani
Super User
Super User

Hi @Dilip7 ,

The error indicates that you are encountering a problem with overlapping relationships in your data model, leading to ambiguity in Power BI. 

Check the Model relationship

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.

 

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.

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).

To calculate the cumulative agent bucket based on all agents till the selected date:

CumulativeAgents =
CALCULATE(
    COUNTROWS('Table B'),
    FILTER(
        ALL('Table B'[Key_Agent_MonthYear]),
        'Table B'[Key_Agent_MonthYear] <= MAX('Table A'[Key_Agent_MonthYear])
    )
)

To calculate agent buckets for a specific month, use the USERRELATIONSHIP function to leverage the inactive relationship:

MonthlyAgents =
CALCULATE(
    COUNTROWS('Table B'),
    USERELATIONSHIP('Table A'[Key_Agent_MonthYear], 'Table B'[Key_Agent_MonthYear])
)
 

To group by agent bucket:

SalesByBucket =
SUMMARIZE(
    'Table B',
    'Table B'[Agent Bucket],
    "Total Sales", SUM('Table A'[Sales]),
    "Cumulative Agents", [CumulativeAgents],
    "Active Agents", [MonthlyAgents]
)

 

If you experience slowness:

Ensure your data model is optimized, with fewer calculated columns and a star schema structure.

Pre-aggregate or calculate buckets in Power Query if the dataset size is manageable.

 

Please mark this as solution if it helps you. Appreciate Kudos

View solution in original post

1 REPLY 1
FarhanJeelani
Super User
Super User

Hi @Dilip7 ,

The error indicates that you are encountering a problem with overlapping relationships in your data model, leading to ambiguity in Power BI. 

Check the Model relationship

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.

 

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.

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).

To calculate the cumulative agent bucket based on all agents till the selected date:

CumulativeAgents =
CALCULATE(
    COUNTROWS('Table B'),
    FILTER(
        ALL('Table B'[Key_Agent_MonthYear]),
        'Table B'[Key_Agent_MonthYear] <= MAX('Table A'[Key_Agent_MonthYear])
    )
)

To calculate agent buckets for a specific month, use the USERRELATIONSHIP function to leverage the inactive relationship:

MonthlyAgents =
CALCULATE(
    COUNTROWS('Table B'),
    USERELATIONSHIP('Table A'[Key_Agent_MonthYear], 'Table B'[Key_Agent_MonthYear])
)
 

To group by agent bucket:

SalesByBucket =
SUMMARIZE(
    'Table B',
    'Table B'[Agent Bucket],
    "Total Sales", SUM('Table A'[Sales]),
    "Cumulative Agents", [CumulativeAgents],
    "Active Agents", [MonthlyAgents]
)

 

If you experience slowness:

Ensure your data model is optimized, with fewer calculated columns and a star schema structure.

Pre-aggregate or calculate buckets in Power Query if the dataset size is manageable.

 

Please mark this as solution if it helps you. Appreciate Kudos

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.