Forum Discussion

Braytron5's avatar
Braytron5
New Member
1 year ago
Solved

Comparing and Calculating Sales for Two Independent Date Periods with Percentage Difference

Hello everyone, I am working on a Power BI report where I want to compare sales (Net total) for two different time periods and then calculated difference show in percentage. I created two table visu...
  • danextian's avatar
    1 year ago

    Hi Braytron5 

     

    That isn't how crossfiltering works. While you can make a viz crossfilter  only a  specific viz, you cannot make it partially do so such that only a column or a measure is affected - it either crossfilters or it doesnt at all. In order to make a two-period comparison, you can't be using a range slicer as there aren't two ranges in there - only one - from the start to end date. A way to achieve this is by using a disconnected table for one of the measures. A disconnected date table can be created by referencing the related date table in a calculated table or by creating one in the query editor without relating it to the other fact/dim tables.

    In the sceenshot  below, Period1 is just a simple as this will be filtered by the related date table.

    Sales = 
    SUM ( Sales[Sales Amount] )

     Period2 is as follows

    Sales Period2 = 
    CALCULATE (
        [Sales], 
        // Map the selected dates from the DisconnectedDate table to the 'Date' table, maintaining any existing filters on DisconnectedDate[Date].
        KEEPFILTERS ( TREATAS ( VALUES ( DisconnectedDate[Date] ), 'Date'[Date] ) ), 
        // Remove any filters applied directly to the 'Date' table to ensure TREATAS controls the filtering.
        REMOVEFILTERS ( 'Date' )
    )
    

    Please see sample pbix for the details.