Forum Discussion
Calculating new column using row values from same table: circular dependency; avoiding EARLIER?
- Anonymous7 years ago
Hi Jimmy,
Thanks for your proposition. I have never used RANKX before....
In the meantime, I could get rid of the circular dependency problem I had by using DISTINCT instead of VALUES in my CALCULATE new column:
Status_after_Mutation = CALCULATE( DISTINCT(LogTable[New_Value]); TOPN( 1; CALCULATETABLE( LogTable; ALLEXCEPT(LogTable; LogTable[Object_ID]); LogTable[Mutation_Parameter] = "Status"; LogTable[Mutation_Date] <= EARLIER(LogTable[Mutation_Date]) ); LogTable[Mutation_Date]; DESC ) )Also, I corrected the column to be "Status_after_Mutation" using the LogTable[New_Value].
Now I am getting what I want (see marked column below):
In the last column, I have also included what I got with your proposition:
Status_before_Mutation = VAR Ranking = RANKX(FILTER(LogTable, LogTable[Object_ID] = EARLIER(LogTable[Object_ID]) && LogTable[Mutation_Date] <= EARLIER(LogTable[Mutation_Date])), RANKX(ALL(LogTable), LogTable[Mutation_Date]), , DESC, Dense) RETURN IF(Ranking = 1, LogTable[New_Value])
I have two questions now:
- Your solution only provides the status for a status mutation. I tried to modify it without success, as I don't quite understand the use of RANKX within RANKX. How should I modify it to get the current status for all mutations on the same object?
- With my solution using TOPN on a big mutation table (> 200,000 rows), I get the following error from PowerBI
"There is not enough memory to complete this operation. Please try again later when there may be more memory available".
Is RANKX or another approach more memory efficient on big tables? Of course I could first split the table in smaller tables before computing the new columns but if I could avoid it with a better method, that would be interesting.Thanks
Karim
Hi Karim11,
Modify your calculate column using DAX below and check if it can meet your requirement:
Status_before_Mutation = VAR Ranking = RANKX(FILTER(LogTable, LogTable[Object_ID] = EARLIER(LogTable[Object_ID]) && LogTable[Mutation_Date] <= EARLIER(LogTable[Mutation_Date])), RANKX(ALL(LogTable), LogTable[Mutation_Date]), , DESC, Dense) RETURN IF(Ranking = 1, LogTable[New_Value])
Regards,
Jimmy Tao
Hi Jimmy,
Thanks for your proposition. I have never used RANKX before....
In the meantime, I could get rid of the circular dependency problem I had by using DISTINCT instead of VALUES in my CALCULATE new column:
Status_after_Mutation =
CALCULATE(
DISTINCT(LogTable[New_Value]);
TOPN(
1;
CALCULATETABLE(
LogTable;
ALLEXCEPT(LogTable; LogTable[Object_ID]);
LogTable[Mutation_Parameter] = "Status";
LogTable[Mutation_Date] <= EARLIER(LogTable[Mutation_Date])
);
LogTable[Mutation_Date];
DESC
)
) Also, I corrected the column to be "Status_after_Mutation" using the LogTable[New_Value].
Now I am getting what I want (see marked column below):
In the last column, I have also included what I got with your proposition:
Status_before_Mutation = VAR Ranking = RANKX(FILTER(LogTable, LogTable[Object_ID] = EARLIER(LogTable[Object_ID]) && LogTable[Mutation_Date] <= EARLIER(LogTable[Mutation_Date])), RANKX(ALL(LogTable), LogTable[Mutation_Date]), , DESC, Dense) RETURN IF(Ranking = 1, LogTable[New_Value])
I have two questions now:
- Your solution only provides the status for a status mutation. I tried to modify it without success, as I don't quite understand the use of RANKX within RANKX. How should I modify it to get the current status for all mutations on the same object?
- With my solution using TOPN on a big mutation table (> 200,000 rows), I get the following error from PowerBI
"There is not enough memory to complete this operation. Please try again later when there may be more memory available".
Is RANKX or another approach more memory efficient on big tables? Of course I could first split the table in smaller tables before computing the new columns but if I could avoid it with a better method, that would be interesting.
Thanks
Karim