Forum Discussion

Harper146's avatar
Harper146
Regular Visitor
8 years ago
Solved

Dax Formula Help - Filters

Hi, I'm new to Power BI and the DAX language. I'm struggling to filter my calculated measure by a dimension. The below Dax formula calculates the previous months new customers in a custom financial...
  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi Harper146,

     

    You can try to use below measure to calculate difference:

    Measure =
    VAR fiscYear =
        SELECTEDVALUE ( Table1[Fiscal Year ] )
    VAR fiscPeriod =
        SELECTEDVALUE ( Table1[Fiscal Period] )
    VAR currProduct =
        SELECTEDVALUE ( Table1[Product] )
    RETURN
        CALCULATE (
            SUM ( Table1[New Customers] ),
            VALUES ( Table1[Fiscal Year] ),
            VALUES ( Table1[Fiscal Period] ),
            VALUES ( Table1[Product] )
        )
            - CALCULATE (
                SUM ( Table1[New Customers] ),
                FILTER (
                    ALL ( Table1 ),
                    Table1[Product] IN VALUES ( Table1[Product] )
                        && Table1[Fiscal Year]
                            = IF ( fiscPeriod = 1, fiscYear - 1, fiscYear )
                        && Table1[Fiscal Period]
                            = IF ( fiscPeriod = 1, 12, fiscPeriod - 1 )
                )
            )
    

     

    Regards,

    Xiaoxin Sheng