Forum Discussion
Anonymous
4 years agoNot applicable
Conditional filter within calculate function?
I am trying to create a measure that has a conditional filter within the Calculate function. Here is a stripped down version of what I am trying to do. PersonaPortfolio = a table that is fil...
- 4 years ago
Yeah, I think you can refactor it to combine FilterA and IgnoreA like this:
Test = VAR A = CALCULATE ( [...] ) VAR B = CALCULATE ( [...] ) VAR C = CALCULATE ( [...] ) VAR D = CALCULATE ( [...] ) VAR FilterA = FILTER ( fact, IF ( ISEMPTY ( A ), NOT fact[A] IN A, fact[A] IN A ) ) VAR FilterB = FILTER ( fact, IF ( ISEMPTY ( B ), NOT fact[B] IN B, fact[B] IN B ) ) VAR FilterC = FILTER ( fact, IF ( ISEMPTY ( C ), NOT fact[C] IN C, fact[C] IN C ) ) VAR FilterD = FILTER ( fact, IF ( ISEMPTY ( D ), NOT fact[D] IN D, fact[D] IN D ) ) RETURN CALCULATE ( [Delta-P], FilterA, FilterB, FilterC, FilterD )
Anonymous
4 years agoNot applicable
AlexisOlson This worked, thank you!
I have 4 different tables it is referencing, A,B,C, and D. Your example is showing A and B. Due to this, I needed to have 16 of those scenarios listed out in my code. I'm afraid of it getting out of control if I need to add any more tables. Are you familiar with a more concise way to handle this or is the code you provided the only solution?
AlexisOlson
4 years agoSuper User
Yeah, I think you can refactor it to combine FilterA and IgnoreA like this:
Test =
VAR A = CALCULATE ( [...] )
VAR B = CALCULATE ( [...] )
VAR C = CALCULATE ( [...] )
VAR D = CALCULATE ( [...] )
VAR FilterA = FILTER ( fact, IF ( ISEMPTY ( A ), NOT fact[A] IN A, fact[A] IN A ) )
VAR FilterB = FILTER ( fact, IF ( ISEMPTY ( B ), NOT fact[B] IN B, fact[B] IN B ) )
VAR FilterC = FILTER ( fact, IF ( ISEMPTY ( C ), NOT fact[C] IN C, fact[C] IN C ) )
VAR FilterD = FILTER ( fact, IF ( ISEMPTY ( D ), NOT fact[D] IN D, fact[D] IN D ) )
RETURN
CALCULATE ( [Delta-P], FilterA, FilterB, FilterC, FilterD )- Anonymous4 years agoNot applicable
AlexisOlson This is exactly what I was looking for! Thank you so much!