Forum Discussion

elguestca1's avatar
elguestca1
Icon for Advocate I rankAdvocate I
2 years ago
Solved

Creating 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...
  • johnt75's avatar
    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
        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.