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
Aldimar_Junior
Frequent Visitor

Need help with circular dependency in measure that needs to use itself to produce the correct value

Hello everyone! hope yall doing great..

I need help returning a dax measure based on the value of the previous i.e:

1) My current table goes as follows:

  • TOTAL_SALES = SUM of all sales
  • TOTAL_COST = SUM of product related expenses
  • TOTAL_EXPENSES = SUM of office related expenses
  • TOTAL_PROFIT = (TOTAL_SALES) - (TOTAL_COST + TOTAL_EXPENSES)

Note: Every value comes from a single field in my DB -> "VALUE", for every measure I calculate "VALUE" using a filter of "TYPE" i.e:
TOTAL_SALES = CALCULATE( SUM( VALUE ), TYPE = "SALES" )... and so on.

 

The types are -> "1 - SALES", "2 - COST", "3 - EXPENSES"

 

This gives me the following:

OFFICE ID |MONTH |TOTAL_SALES |TOTAL_COST |TOTAL_EXPENSES |TOTAL_PROFIT |

01

JUN14.260.2649.006.0392.074.2963.179.929
01JUL14.855.8941.800.7631.362.67911.692.452
01AUG14.188.5733.343.2911.408.3099.436.973

 

The problem I'm facing is: I need to calculate "TOTAL_SALES" using the "TOTAL_PROFIT" of the last month as a starting point and if there's no "last month" I need to use a given value instead i.e:

"Default start value = 20.000.000"
"last_month_val = TOTAL_PROFIT(LAST_MONTH)

JUN has no "last_month_val" use "Default start value"
TOTAL_SALES = CALCULATE( SUM( VALUE ), TYPE = "SALES") + last_month_val

The thing I cant figure out/get working is the "last_month_val" part.... I already tried "PREVIOUSMONTH", CALCULATE using DATEADD(DATE, -1, MONTH) as filter, CALCULATE using EDATE(DATE, -1)...

2) To "compile it all" the desired result would be: 

 

  • JUN starts with +20.000.000 since theres no previous month to look at.
  • NEW_TOTAL_SALES = TOTAL_SALES + PREVIOUS_MONTH.
  • TOTAL_COST and TOTAL_EXPENSES stays the same.
  • TOTAL_PROFIT is now calculated based on the new "TOTAL_SALES" value.
OFFICE ID |MONTH |PREVIOUS_MONTH |TOTAL_SALES |NEW_TOTAL_SALES |TOTAL_COST |TOTAL_EXPENSES |TOTAL_PROFIT |
01JUN20.000.00014.260.26434.260.2649.006.0392.074.29623.179.929
01JUL23.179.92914.855.89438.035.8231.800.7631.362.67934.872.381
01AUG34.872.38114.188.57349.060.9543.343.2911.408.30944.309.354

 

Can anyone give me a hand/direction to follow?

2 REPLIES 2
Aldimar_Junior
Frequent Visitor

I created a xlsx with the expected result I need, The formulas/Calculations used and some sample data:

Expected result.xlsx 

Aldimar_Junior
Frequent Visitor

Update, I got "most" of it working....
imagem_2023-10-20_101930609.png

 

The formula goes like this:

  • sum_prev_curr = val_previous_month + val_curr_month
  • profit (green - red) = sum_prev_curr - ( total_expenses(prod) + total_expenses(off) )

 

The problem.. val_previous_month should be the value of profit (green - red) from the previous month (as said by the name) but when I try return the value of profit (green - red) "-1 month" into val_previous_month I get circular dependencies errors... heres what I have currently:

val_previous_month =

_def_initial_val = 20000000

// TIME INTELLIGENCE --------------------------------------------------------------------------
// Return the value of the "lowest" month available in the database
VAR _min_month = MONTH(DATEVALUE(CALCULATE(
    MIN('Table Name (X)'[Order Date]),
    ALL('Table Name (X)')
)))

// Return the value of the current selected month (per row)
VAR _this_month = SELECTEDVALUE('Table Name (X)'[Order Date].[MonthNo])

// Return the value of the current selected month - 1 [PREVIOUS] (per row)
VAR _prev_month = (_this_month - 1)

// Verify if selected month is the lowest month in the DB
VAR _verify = IF(_this_month = _min_month, "Lowest", "-")
// --------------------------------------------------------------------------------------------

// Return the value of "profit" from previous month
VAR _prev_month_profit = 
CALCULATE([profit (green - red)],
    FILTER(ALL('Table Name (X)'), 
        'Table Name (X)'[Order Date].[MonthNo] = _prev_month
    )
)

// If the selected month is the lowest, return a sum of "total sales" + "initial value"
// else return the value of "profit" from previous month
VAR _sumif = IF(_verify = "Lowest",
    [total_sales] + _def_initial_val,
    _prev_month_profit
)

RETURN
    _sumif


I really don't know how to solve this issue with circular dependency...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors