Forum Discussion

analyticspbi87's avatar
1 year ago
Solved

Circular Dependency when using variable in measures

Hi there,

 

Currently, I'm trying to get two different measures to show as follows and am getting an error on the second variable.

BuildingYearValueType CostTypeValue ThousandsGroup TOTAL A  TOTAL B Multiplier
A2021123Amort YearRecoverable500B                    5,000.00                   6,000.001.5
A2021123Add YearRecoverable100A                    5,000.00                   6,000.001.3
A2022124Add YearRecoverable30B                    5,000.00                   6,000.001.69
A2023125Add YearNon-Recoverable200B                    5,000.00                   6,000.001.4
A2024126Add YearNon-Recoverable0B                    5,000.00                   6,000.001.5
A2025127Add YearNon-Recoverable0B                    5,000.00                   6,000.001.8
B2021123Add YearRecoverable500A                    3,000.00                   4,000.001.3
B2022124Add YearRecoverable100B                    3,000.00                   4,000.001.69
B2023124Add YearNon-Recoverable30B                    3,000.00                   4,000.001.4
B2024124Add YearNon-Recoverable200B                    3,000.00                   4,000.001.5
B2025125Add YearNon-Recoverable0B                    3,000.00                   4,000.001.8
B2021125Amort YearNon-Recoverable0B                    3,000.00                   4,000.001

 

 

The calculation I'm using is as follows. The following returns a 0

% of TOTAL A
VAR ANUMERATOR =
DIVIDE(
    CALCULATE(
    SUM('Data'[Value]),
    'Data'[Group]<>"A" &&
    'Data'[Type Cost]="Add Year"),
    1000)
    VAR ADENOMINATOR =
    DIVIDE(
    (SUM(Data'[Multiplier])*SUM('Data'[TOTAL A])),
    1000)
    RETURN ANUMERATOR/ADENOMINATOR

 

% of TOTAL B
VAR BNUMERATOR =
DIVIDE(
    CALCULATE(
    SUM('Data'[Value]),
    'Data'[Group]<>"A" &&
    'Data'[Type Cost]="Add Year"&&
     'Data'[Type]="Non-Recoverable"),
    1000)
    VAR BDENOMINATOR =
    DIVIDE(
    (SUM(Data'[Multiplier])*SUM('Data'[TOTAL B])),
    1000)
    RETURN BNUMERATOR/BDENOMINATOR

 

Just wondering if anyone has any better formulas that can be used? When I split out the denominators and numerators, I kept getting errors.

 

  • You have a couple of typos in your formulas, but there is no circular dependency anywhere.

     

     

    % of TOTAL A = 
    VAR ANUMERATOR =
        DIVIDE (
            CALCULATE (
                SUM ( 'Data'[Value] ),
                'Data'[Group] <> "A",
                'Data'[Type Cost] = "Add Year"
            ),
            1000
        )
    VAR ADENOMINATOR =
        DIVIDE ( SUM ( 'Data'[Multiplier] ) * SUM ( Data[ TOTAL A ] ), 1000 )
    RETURN
        DIVIDE ( ANUMERATOR, ADENOMINATOR )
    
    % of TOTAL B =
    VAR BNUMERATOR =
        DIVIDE (
            CALCULATE (
                SUM ( 'Data'[Value] ),
                'Data'[Group] <> "A",
                'Data'[Type Cost] = "Add Year",
                'Data'[Type] = "Non-Recoverable"
            ),
            1000
        )
    VAR BDENOMINATOR =
        DIVIDE ( ( SUM ( 'Data'[Multiplier] ) * SUM ( 'Data'[ TOTAL B ] ) ), 1000 )
    RETURN
        DIVIDE ( BNUMERATOR, BDENOMINATOR )

     

3 Replies

  • You have a couple of typos in your formulas, but there is no circular dependency anywhere.

     

     

    % of TOTAL A = 
    VAR ANUMERATOR =
        DIVIDE (
            CALCULATE (
                SUM ( 'Data'[Value] ),
                'Data'[Group] <> "A",
                'Data'[Type Cost] = "Add Year"
            ),
            1000
        )
    VAR ADENOMINATOR =
        DIVIDE ( SUM ( 'Data'[Multiplier] ) * SUM ( Data[ TOTAL A ] ), 1000 )
    RETURN
        DIVIDE ( ANUMERATOR, ADENOMINATOR )
    
    % of TOTAL B =
    VAR BNUMERATOR =
        DIVIDE (
            CALCULATE (
                SUM ( 'Data'[Value] ),
                'Data'[Group] <> "A",
                'Data'[Type Cost] = "Add Year",
                'Data'[Type] = "Non-Recoverable"
            ),
            1000
        )
    VAR BDENOMINATOR =
        DIVIDE ( ( SUM ( 'Data'[Multiplier] ) * SUM ( 'Data'[ TOTAL B ] ) ), 1000 )
    RETURN
        DIVIDE ( BNUMERATOR, BDENOMINATOR )

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, analyticspbi87 

    Do you have to use calculated columns, please? Can you use Measure?


    Can you share the results you expect to get and the logic behind the calculation?

     

    We will do our best to help you solve the problem you are having.

     

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Fen Ling,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.