Forum Discussion
Assign different value based on other column's value
- 1 year ago
Hi maryfree86
Sorry for the late response.
Thank you for being part of the Microsoft Fabric Community.The error you're getting "A circular dependency was detected" — is due to the calculated column referencing itself ([Assign Value]) inside its own logic. DAX calculated columns cannot look forward or access their own value while being evaluated row by row.
You want to check for previous rows with the same ID, Date, and Frequency, and reuse the assign value from there if matched, otherwise generate a new value "AAA" & Index.
To avoid the circular reference, we must calculate this without ever referring to [Assign Value] itself.
Please check the updated Dax as follows:
-----------------------------------------------------------
Assign Value =VAR CurrentIndex = 'Table'[Index]
VAR CurrentID = 'Table'[ID]
VAR CurrentDate = 'Table'[Date]
VAR CurrentFreq = 'Table'[Freq]
VAR MatchedIndex =
CALCULATE(
MIN('Table'[Index]),
FILTER(
'Table',
'Table'[Index] < CurrentIndex &&
'Table'[ID] = CurrentID &&
'Table'[Date] = CurrentDate &&
'Table'[Freq] = CurrentFreq
)
)
RETURN
IF(
ISBLANK(MatchedIndex),
"AAA" & CurrentIndex,
"AAA" & MatchedIndex
)
-----------------------------------------------------------
If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth.
Try this:
Column E =
VAR CurrentRow = 'Table'[Row ID] -- Replace Row ID with a unique identifier for each row
VAR PrevRow =
CALCULATE(
MAX('Table'[Row ID]),
FILTER(
'Table',
'Table'[Row ID] < CurrentRow
)
)
VAR SameRow =
IF (
'Table'[Column B] = CALCULATE(MAX('Table'[Column B]), FILTER('Table', 'Table'[Row ID] = PrevRow)) &&
'Table'[Column C] = CALCULATE(MAX('Table'[Column C]), FILTER('Table', 'Table'[Row ID] = PrevRow)) &&
'Table'[Column D] = CALCULATE(MAX('Table'[Column D]), FILTER('Table', 'Table'[Row ID] = PrevRow)),
TRUE,
FALSE
)
RETURN
IF(SameRow,
'Table'[Column E],
"AAA" & CurrentRow
)
or
Column E =
VAR CurrentB = 'Table'[Column B]
VAR CurrentC = 'Table'[Column C]
VAR CurrentD = 'Table'[Column D]
VAR NextRow =
CALCULATE(
MAX('Table'[Column E]),
FILTER(
'Table',
'Table'[Column B] = CurrentB &&
'Table'[Column C] = CurrentC &&
'Table'[Column D] = CurrentD &&
'Table'[Index] < EARLIER('Table'[Index]) -- Assuming 'Index' is a sequential column
)
)
RETURN
IF(ISBLANK(NextRow), "AAA" & EARLIER('Table'[Index]), NextRow)
Hi Shravan133 ,
I tried the formular that you provided above for both, it seems like none of them working. Since I put 'Table'[Column E](replace with my table and comlun name), it gives error. Not sure if when I created new column, I can refer to the new column name in the formula