Forum Discussion

SavioFerraz's avatar
SavioFerraz
Icon for Super User rankSuper User
8 months ago
Solved

Power BI – YoY Measure Ignoring Product Filter but Respecting Slicers

Hi everyone,   I’m working on an intermediate Power BI scenario and need some guidance. I have Sales data by Product and Date, and I need a measure that shows Year-over-Year % change, but it must ...
  • ryan_mayu's avatar
    8 months ago

    SavioFerraz 

    have you tried all[product]?

     

    YoY % Change=
    VAR CurrentSales = CALCULATE([Total Sales], ALL('Product'))
    VAR LastYearSales = CALCULATE([Total Sales], ALL('Product'), SAMEPERIODLASTYEAR('Date'[Date]))
    RETURN
    DIVIDE(CurrentSales - LastYearSales, LastYearSales)

     

     

    if this does not work, pls provide some sample data and expected output.

  • danextian's avatar
    8 months ago

    Hi SavioFerraz 

     

    If by product fitlers you mean all product-related filters and not simply product name or category, there must be sepaerate dimension table for this and in a  measure you use either REMOVEFILTERS or ALL

     

    In the image below, REMOVEFILTERS is applied to the Category table so the third measure returns the same previous year value for all categories. The columns from Category table must be used in the visual for this to work and not the fact column used in a relationship

     

  • Kedar_Pande's avatar
    8 months ago

    SavioFerraz 

     

    YoY % =
    VAR CurrentValue = [Sales]
    VAR PriorYearValue =
    CALCULATE(
    [Sales],
    SAMEPERIODLASTYEAR(Date[Date]),
    REMOVEFILTERS(Product)

    )
    RETURN
    DIVIDE(CurrentValue - PriorYearValue, PriorYearValue)

     

    If this answer helped, please click Kudos or Accept as Solution.
    -Kedar
    LinkedIn: https://www.linkedin.com/in/kedar-pande

  • cengizhanarslan's avatar
    8 months ago
    YoY % (Ignore Product) =
    VAR SalesCY =
        CALCULATE ( [Sales], REMOVEFILTERS ( 'Product' ) )
    VAR SalesPY =
        CALCULATE (
            [Sales PY],                      -- e.g. CALCULATE([Sales], SAMEPERIODLASTYEAR('Calendar'[Date]))
            REMOVEFILTERS ( 'Product' )
        )
    RETURN
    DIVIDE ( SalesCY - SalesPY, SalesPY )

     

    That keeps Date and Region slicers working (because you’re not touching those tables), but any filter coming from Product (slicer, row/column headers, cross-highlighting) is ignored.

  • CPCARDOSO's avatar
    8 months ago

    Oi Savio, espero que isso te ajude...

    If this helped you, please give me some kudos! 👍 It motivates me to keep sharing solutions with the community.

     

    Sales Ignoring Product

    Sales (Ignore Product) :=
    CALCULATE (
        [Sales],
        REMOVEFILTERS ( DimProduct )      -- ou ALL ( DimProduct )
    )
     
    Previous Year Sales (Still Ignoring Product)

    Sales LY (Ignore Product) :=
    CALCULATE (
        [Sales (Ignore Product)],
        DATEADD ( DimDate[Date], -1, YEAR )
    )
     If your calendar is not continuous or has gaps, you can replace with SAMEPERIODLASTYEAR ( DimDate[Date] ).

     

    YoY % Change (Ignoring Product, Respecting Date/Region)

    YoY % (Ignore Product) :=
    VAR Curr = [Sales (Ignore Product)]
    VAR Prev = [Sales LY (Ignore Product)]
    RETURN
    DIVIDE ( Curr - Prev, Prev )
    ``

     

    If you have more than one product-related table (e.g., category/brand), clear them all:
    CALCULATE ( [Sales], REMOVEFILTERS ( DimProduct, DimBrand, DimCategory ) )
     
    Power BI – YoY Measure Ignoring Product Filter (But Respecting Date & Region)

    Sales :=
    SUM ( Sales[Amount] )
    Sales (Ignore Product) :=
    CALCULATE (
        [Sales],
        REMOVEFILTERS ( DimProduct )
    )

    Sales LY (Ignore Product) :=
    CALCULATE (
        [Sales (Ignore Product)],
        DATEADD ( DimDate[Date], -1, YEAR )
    )

    YoY % (Ignore Product) :=
    VAR Curr = [Sales (Ignore Product)]
    VAR Prev = [Sales LY (Ignore Product)]
    RETURN
    DIVIDE ( Curr - Prev, Prev )
     
    Note: This text was translated using AI for better understanding by the forum and community.

  • Bibiano_Geraldo's avatar
    8 months ago

    Hi SavioFerraz ,
    Please try the bellow measure and let me know if help you.

    NOTE: change the table and column names with your own

    YoY % Change = 
    VAR CurrentYearSales = 
        CALCULATE(
            SUM(Sales[Amount]),
            ALL(Products)
        )
    
    VAR PreviousYearSales = 
        CALCULATE(
            SUM(Sales[Amount]),
            ALL(Products),
            DATEADD(Dates[Date], -1, YEAR)
        )
    
    VAR YoYChange = 
        DIVIDE(
            CurrentYearSales - PreviousYearSales,
            PreviousYearSales
        )
    
    RETURN 
    YoYChange