Forum Discussion
Issue with measure as a filter
Hello,Fowmy ,thanks for your concern about this issue.
Your answer is excellent!
And I would like to share some additional solutions below.
Hi,Bimbone .I am glad to help you.
I noticed your original code :
CALCULATE(
FIRSTNONBLANK('CoppeCitta'[SFPair],1), FILTER(
'CoppeCitta',
related(Cities[ID_City])=SelectedCitta&&
RELATED(Cities_numbers[YR])=SelectedYR&&
CoppeCitta[Competizione]=selectedComp
)
)
The table here does not perform the operation of removing external filtering conditions.
The FILTER function considers external filtering conditions in the context of its calculations, which can result in the returned value being influenced by the current row. To avoid this, you can use the ALL function to remove external filtering conditions, thus ensuring that the FILTER function only considers the conditions you specify.
You can try modifying the table using ALL()/ALLSELECTED()/ALLEXCEPT().
You could try the following modifications
CorrespondingMatchSF =
VAR SelectedCitta = SELECTEDVALUE(Cities[ID_City])
VAR SelectedYR = SELECTEDVALUE(Cities_numbers[YR])
VAR selectedComp = SELECTEDVALUE(CoppeCitta[Competizione])
RETURN
CALCULATE(
SELECTEDVALUE('CoppeCitta'[SFPair]),
FILTER(
ALL('CoppeCitta'),
RELATED(Cities[ID_City]) = SelectedCitta &&
RELATED(Cities_numbers[YR]) = SelectedYR &&
CoppeCitta[Competizione] = selectedComp
)
)
Otherwise, as you currently write it, there is a good chance that the internal data of the measure being calculated will be affected by the current row of the table visual itself, which will affect the final result.
Double-checking your real computing environment is, I think, the key to solving your problem.
For the SELECTEDVALUE() function, which returns null when multiple values are selected for the same slicer field, you might want to try using an aggregate function such as MAX/MIN instead of just SELECTEDVALUE!
Regarding the link to the pbix file you provided subsequently, unfortunately I can't access it due to environmental constraints. You might try using the unencrypted OneDrive /GitHub link to analyze your test data.
You can also additionally provide some test data simulating your real environment and screenshots of what to expect .
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Carson,
thank you for your reply.
I am now travelling for a few days, but when I am back next week I will test your solution and will let you know!