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.
Hi maryfree86
Sorry for the late response.
Yes, when creating a calculated column in Power BI using DAX, you cannot refer to the same column (Assign value) that is being created within its own formula.
Instead, you need an approach that iterates through previous rows while ensuring proper assignment.
Please use updated DAX formula that resolve your issue:
*********************************************************************
Assign Value =
VAR CurrentIndex = 'Table'[Index]
VAR CurrentID = 'Table'[ID]
VAR CurrentDate = 'Table'[Date]
VAR CurrentFreq = 'Table'[Freq]
VAR PrevAssignValue =
CALCULATE(
MAX('Table'[Assign Value]),
FILTER(
'Table',
'Table'[Index] < CurrentIndex &&
'Table'[ID] = CurrentID &&
'Table'[Date] = CurrentDate &&
'Table'[Freq] = CurrentFreq
)
)
RETURN
IF(
ISBLANK(PrevAssignValue),
"AAA" & CurrentIndex,
PrevAssignValue
)
*********************************************************************
If the above information helps you, please give us a Kudos and marked the reply Accept as a Solution.
Thanks,
Cheri Srikanth
Hi v-csrikanth ,
I am still having error "A circular dependency was detected: 'Table'[Assign Value]."