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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AUaero
Responsive Resident
Responsive Resident

Calculated table generates a circular dependency when joined

Hi,

I've built a calculated table to rank salespeople based on several metrics over the last 365 days.  Here's the code:

 

Magnolia Club ISR = 
VAR tblData = 
CALCULATETABLE(
	ADDCOLUMNS(
		SELECTCOLUMNS(
			FILTER(
				ALLNOBLANKROW(ISR),
				ISR[ISRJobTitle] in  {"Inside Sales ONS", "Inside Sales Trainee ONS"}
			),
			"ISRName", ISR[ISRName],
			"ISRNumber", ISR[ISRNumber]
		),
		"BilledGrossMargin", 'Sales Order'[$ Billed WAC GM],
		"BilledTons", 'Sales Order'[# Billed Tons],
		"BuyingPRONTOAccounts", Customer[# Buying PRONTO Customers],
		"BilledProcessedGM", 'Sales Order'[$ Billed Processed GM],
		"BilledSpecialtyGM", 'Sales Order'[$ Billed Specialty GM],
		"AdminQDR", 'Sales Order'[% QDR - Admin]
	),
	FILTER(
		ALLNOBLANKROW('Calendar'[Trailing365DaysFlag]),
		'Calendar'[Trailing365DaysFlag] = "Trailing 365 Days"
	)
)

VAR tblRank = 
ADDCOLUMNS(
	tblData,
	"BilledGrossMarginRank", RANKX(tblData, [BilledGrossMargin], , DESC, Skip),
	"BilledTonsRank", RANKX(tblData, [BilledTons], , DESC, Skip),
	"BuyingPRONTOAccountsRank", RANKX(tblData, [BuyingPRONTOAccounts], , DESC, Skip),
	"BilledProcessedGMRank", RANKX(tblData, [BilledProcessedGM], , DESC, Skip),
	"BilledSpecialtyGMRank", RANKX(tblData, [BilledSpecialtyGM], , DESC, Skip),
	"AdminQDRRank", RANKX(tblData, [AdminQDR], , DESC, Skip)
)

VAR tblRankSum = 
ADDCOLUMNS(
	tblRank,
	"RankSum", [BilledGrossMarginRank] + [BilledTonsRank] + [BuyingPRONTOAccountsRank] + [BilledProcessedGMRank] + [BilledSpecialtyGMRank] + [AdminQDRRank]
)

RETURN 
ADDCOLUMNS(
	tblRankSum,
	"OverallRank", RANKX(tblRankSum, [RankSum], , ASC, Skip)
)

 

The problem arises when I try to join this calculated table back to my salesperson table (ISR) on the ISRNumber field:

AUaero_0-1638217717657.png

However, when I try to do this I get a circular dependency.  I've tried eliminating the blank row as a factor in the join to eliminate the dependency per the SQLBI blog (Understanding circular dependencies in DAX - SQLBI) but I'm still running into problems.

Any ideas?

Thanks!

 

1 ACCEPTED SOLUTION
AUaero
Responsive Resident
Responsive Resident

Update 2 - the fix was easy enough, even if figuring out the problem with circular dependency isn't always evident.  By eliminating the blank row on the Customer table I was able to successfully build the realtionship in my data model.  My new measure is:

# Buying PRONTO Customers = 
SUMX(
    ALLNOBLANKROW(Customer),
    SWITCH(
        TRUE(),
        Customer[# E1 Buying PRONTO Customers] > 0, 1,
        Customer[# CMA Buying PRONTO Customers] > 0, 1
    )
)

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi @AUaero ,

 

You can try restrict the list of columns that the calculated column depends on, by using ALLEXCEPT or REMOVEFILTERS and keeping only the table’s primary key. If the table has no primary key, then using CALCULATE in a calculated column is dangerous.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AUaero
Responsive Resident
Responsive Resident

Update - 
Further troubleshooting has narrowed it down to a particular measure that is causing the problem.  The column "BuyingPRONTOAccounts" on variable "tblData" is generated from a measure on the "Customer" table named "# Buying PRONTO Customers".
# Buying PRONTO Customers is calculated from two other measures, "# E1 Buying PRONTO Customers" and "# CMA Buying PRONTO Customers".

# Buying PRONTO Customers = 
SUMX(
    Customer,
    SWITCH(
        TRUE(),
        Customer[# E1 Buying PRONTO Customers] > 0, 1,
        Customer[# CMA Buying PRONTO Customers] > 0, 1
    )
)

# E1 Buying PRONTO Customers = 
CALCULATE(
    Customer[# E1 Buying Customers],
    'E1 Sales'[DocType] = "SH"
)

# CMA Buying PRONTO Customers = 
CALCULATE(
    Customer[# CMA Buying Customers],
    Channel[Channel] = "Pronto"
)

If I modify the BuyingPRONTOAccounts column in tblData to reflect either # E1 Buying PRONTO Customers or # CMA Buying PRONTO Customers, I don't get a circular dependency on the join between ISR and Customer.

How can I modify # Buying PRONTO Accounts to eliminate the circular dependency?
Thanks!



AUaero
Responsive Resident
Responsive Resident

Update 2 - the fix was easy enough, even if figuring out the problem with circular dependency isn't always evident.  By eliminating the blank row on the Customer table I was able to successfully build the realtionship in my data model.  My new measure is:

# Buying PRONTO Customers = 
SUMX(
    ALLNOBLANKROW(Customer),
    SWITCH(
        TRUE(),
        Customer[# E1 Buying PRONTO Customers] > 0, 1,
        Customer[# CMA Buying PRONTO Customers] > 0, 1
    )
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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