Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

If with selectedvalue

Hi Experts   I need a if condition with a selected value in DAX. So if the user does not selects a Region then Contribution Margin = VAR Mth1 = SELECTEDVALUE ( SelMth_Current[Month] ) VAR yr ...
  • v-janeyg-msft's avatar
    5 years ago

    Hi, Anonymous 

     

    According to your description, I think you can use 'isfiltered' function in measure.

    Like this:

    Contribution Margin =
    VAR Mth1 =
        SELECTEDVALUE ( SelMth_Current[Month] )
    VAR yr =
        SELECTEDVALUE ( SelYr[Year] )
    VAR Fcst1 =
        SELECTEDVALUE ( SelMth4[Actual] )
    VAR Prod =
        SELECTEDVALUE ( Product_Grp[Product] )
    VAR Reg =
        SELECTEDVALUE ( Region_Grp[Region] )
    VAR MthVal1 =
        CALCULATE (
            SUM ( Profitability_Consolidation[Profit] ),
            Profitability_Consolidation[Period] = Fcst1,
            Profitability_Consolidation[Month] = Mth1,
            Profitability_Consolidation[Year] = yr,
            Profitability_Consolidation[Product] = Prod,
            Profitability_Consolidation[AccountGroup] = "Contribution Margin"
        )
    VAR MthVal2 =
        CALCULATE (
            SUM ( Profitability_Consolidation[Profit] ),
            Profitability_Consolidation[Period] = Fcst1,
            Profitability_Consolidation[Month] = Mth1,
            Profitability_Consolidation[Year] = yr,
            Profitability_Consolidation[Product] = Prod,
            Profitability_Consolidation[Region] = Reg,
            Profitability_Consolidation[AccountGroup] = "Contribution Margin"
        )
    RETURN
        IF ( ISFILTERED ( 'table'[Region] ), MthVal2 / 1000, MthVal1 / 1000 )

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.