Forum Discussion

Beefheart's avatar
Beefheart
Helper I
3 years ago

Circular Dependency?

Hello,

I have a Customers table that’s linked to a Transactions Table and am using Direct Query mode.

I’ve created a calculated column on the customers table that finds the date of the customer’s earliest sales order:

 

FirstSalesOrderDate =

    CALCULATE(

        MIN('Transactions'[Date]),

        'Transaction'[Type] = "Sales Order"

        && 'Transaction'[State] <> "Closed"

        && 'Transaction'[State] <> "Cancelled"

    )

 

This works as desired.

My problems occur when I try and add a second calculated column to the Customers table that returns a date with just the year and month from the FirstSalesOrderDate. EG: The date 2023-05-24 becomes 2023-05-01:

FirstSOMonthYear =

       DATE(YEAR([FirstSalesOrderDate]), MONTH([FirstSalesOrderDate]), 1)


This creates a circular dependency for some reason, yet FirstSalesOrderDate in no way references FirstSOMonthYear.

I’ve also tried changing the calculated column FirstSOMonthYear to this:

 

firstSOMonthYear =

 VAR theDate = CALCULATE(

        MIN('Transaction Header'[Date]),

        'Transaction Header'[Type] = "Sales Order"

        && 'Transaction Header'[State] <> "Closed"

        && 'Transaction Header'[State] <> "Cancelled"

    )

 

RETURN DATE(YEAR(theDate), MONTH(theDate), 1)

 

This too results in a circular dependency, yet it in no way references the first calculated column.

What I want to know is why I’m seeing this behaviour, and what I can do to avoid it.
Can anyone help please?

3 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Beefheart 

    Please try

    FirstSalesOrderDate =
    MINX (
    FILTER (
    'Transaction',
    'Transaction'[Type] = "Sales Order"
    && 'Transaction'[State] <> "Closed"
    && 'Transaction'[State] <> "Cancelled"
    && 'Transaction'[Customer Key] = 'Customers'[Customer Key]
    ),
    'Transactions'[Date]
    )

    • Beefheart's avatar
      Beefheart
      Helper I

      Hello taberj1,

       

      Thank you for taking the time to consider my problem and reply. But I wasn't after a working dax query, sorry if I implied that.

       

      What I want to know is why it's happening, what's causing this behaviour? And why does it happen when the two columns are in no way referencing each other? I want to learn what the issue is 🙂

       

      Thanks again for your time!

       

      Beefheart