Forum Discussion

HY2024's avatar
HY2024
Frequent Visitor
2 years ago
Solved

Sales analysis vs same period last year

Hello,   I have daily sales in value and in quantities by different boutiques that I would like to compare with the same period last year using a matrix in PowerBI. here is how I proceed: I first...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Thank you rajendraongole1 

    Hi, HY2024 

    According to your description, I used the following sample data:

    I created a calendar table:

    The relationship between the calendar table and the sales table is as follows:

    First, I created the following DAX expression to find the QTY of the current matrix month:

    Current_month_QTY = 
    CALCULATE(
        SUM(financials[ Sales]),
        FILTER('Date table',
            'Date table'[Year] = MAX('Date table'[Year])
        )
    )

    I used the following DAX expression to find the QTY for the same period in the previous year:

    LastYearQTY = CALCULATE(
        SUM(financials[ Sales]),
        SAMEPERIODLASTYEAR('Date table'[Date])
    )

    I use the following DAX expression to create a PercentageOfLastYearSales measure:

    PercentageOfLastYearSales = DIVIDE([Current_month_QTY],[LastYearQTY])

    The results are as follows:

    The reason you are showing 118% all together may be that you are using the ALL function in your DAX expression, which clears all external filters, including the row and column fields placed by your matrix. You can learn about the event intelligence functions in DAX, which will be helpful for you to calculate YTD, QTD, and so on:

    Time intelligence functions (DAX) - DAX | Microsoft Learn

    I have provided the PBIX file used in this instance below.

     

     

    Best Regards

    Jianpeng Li

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