Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Previous Year Sales issue

Hi Experts   See attatched PBIX and the PY measure is in the FACT Sales Table. I am unable to get the previous years sales, if i do its the same value as the current year sales (i.e. 2020)   Samp...
  • daxer-almighty's avatar
    5 years ago

    You don't get what you want because your calendar is screwed up. Also, it's not marked as a date table.

     

    Here are your measures for when you fix your calendar:

     

     

    USD = 
    SWITCH ( SELECTEDVALUE ( DimHierarchy[AccountItem] ),
        "Gross Sales", SUM ( FACTSales[Gross Sales (USD)] ),
        "Rebate", SUM ( FACTSales[Rebate (USD)] ),
        "Net Sales", SUM ( FACTSales[Net Sales (USD)] )
    )

     

     

    and

     

     

    PY = 
    IF( HASONEVALUE( DimDate[Year] ),
        CALCULATE(
            [USD],
            SAMEPERIODLASTYEAR( DimDate[Date] )
        )
    )

     

     

    Measures should never be defined in more than 1 place. Duplication of code is a sign of a bad design and the root of all evil in programming.