Forum Discussion
elguestca1
Advocate I
2 years agoCreating a measure with if condition to return value from the same column
Hello, i was wondering is there a way to write a measure with a condition which refers to a column the result is needed from? I think it may be difficult, so i will try to explain the situation...
- 2 years ago
The below should work, but it will be slow and depending on the size of your data it might not be practicable
Aggregated Value = VAR _CurrentCode = SELECTEDVALUE ( 'Table'[Code] ) VAR Result = IF ( NOT ISBLANK ( _CurrentCode ), CALCULATE ( SUM ( 'Table'[Value] ), CONTAINSSTRING ( 'Table'[Code], _CurrentCode ) ) ) RETURN ResultIdeally you would be able to build a parent child hierarchy which explicitly details which codes belong where, but that isn't always possible.
johnt75
Super User
2 years agoThe below should work, but it will be slow and depending on the size of your data it might not be practicable
Aggregated Value =
VAR _CurrentCode =
SELECTEDVALUE ( 'Table'[Code] )
VAR Result =
IF (
NOT ISBLANK ( _CurrentCode ),
CALCULATE (
SUM ( 'Table'[Value] ),
CONTAINSSTRING ( 'Table'[Code], _CurrentCode )
)
)
RETURN
Result
Ideally you would be able to build a parent child hierarchy which explicitly details which codes belong where, but that isn't always possible.