Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Chris2016
Resolver I
Resolver I

Calculate difference between monthly snapshots in historic table

Hello,

I need some help with the following scenario.
I have a table where I am saving monthly captures of the sales status for Sales People in various departments.

Monthly captureDepartmentSales PersonSales Category# of Items soldLatest Sales Date
Mar-24XACars21/5/2024
Mar-24XAPlanes11/2/2024
Mar-24XABoats31/13/2024
Mar-24XBCars22/4/2024
Mar-24XBPlanes12/5/2024
Mar-24XCCars32/16/2024
Mar-24XCBoats  
Mar-24YDBoats13/8/2024
Mar-24YDCars23/19/2024
Mar-24YDPlanes43/10/2024
Mar-24YEBoats13/11/2024
Mar-24YECars23/12/2024
Mar-24YEPlanes 3/12/2024
Mar-24XF   
Mar-24XG   
Mar-24YH   
Mar-24YI   
Mar-24ZMPlanes41/18/2024
Mar-24ZNBoats13/19/2024
Mar-24ZOCars22/20/2024
Mar-24ZPPlanes  
Apr-24XACars34/5/2024
Apr-24XAPlanes21/2/2024
Apr-24XABoats44/13/2024
Apr-24XBCars34/4/2024
Apr-24XBPlanes12/5/2024
Apr-24XCCars32/16/2024
Apr-24XCBoats  
Apr-24YDBoats13/8/2024
Apr-24YDCars34/19/2024
Apr-24YDPlanes43/10/2024
Apr-24YEBoats34/11/2024
Apr-24YECars23/12/2024
Apr-24YEPlanes 3/12/2024
Apr-24XFCars34/29/2024
Apr-24XGPlanes14/30/2024
Apr-24YH   
Apr-24YI   
Apr-24ZMPlanes41/18/2024
Apr-24ZNBoats13/19/2024
Apr-24ZOCars34/30/2024
May-24XACars34/5/2024
May-24XAPlanes21/2/2024
May-24XABoats44/13/2024
May-24XBCars34/4/2024
May-24XBPlanes12/5/2024
May-24XCCars32/16/2024
May-24XCBoats  
May-24YDBoats35/18/2024
May-24YDCars34/19/2024
May-24YDPlanes43/10/2024
May-24YEBoats34/11/2024
May-24YECars35/12/2024
May-24YEPlanes 3/12/2024
May-24XFCars34/29/2024
May-24XGPlanes35/20/2024
May-24YHCars35/20/2024
May-24YI   
May-24ZMPlanes41/18/2024
May-24ZNBoats35/19/2024
May-24ZOCars34/30/2024
May-24ZOBoats25/1/2024
May-24ZPPlanes35/2/2024
May-24ZQ   


The date (month and year) in column [Monthly capture] is a snapshot at the end of each calendar month. I add new data (current statuses) monthly to the existing data.

I am employing the following measures:

# Sales Person = DISTINCTCOUNT('Monthly Captures'[Sales Person])
 
# Sales People with over 3 items sold =
  COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
        FILTER ( 'Monthly Captures',  'Monthly Captures'[# of Items sold]>=3),
    "@result", 'Monthly Captures'[Sales Person])
     )
    )
// this is the number of sales people who have sold 3 or more items

 

% Sales over 3 =
IFERROR( DIVIDE([# Sales People with over 3 items sold], [# Sales Person], 0),0)
//this is the percent of sales people who have sold 3 or more items calculated against the entire sales population

I am also using the following measure, but it is not exactly what I need, as I need this measure to be unresponsive for the [Monthly capture] filter.

 

% Sales Current Month = 
CALCULATE (
    [% Sales over 3],
   FILTER('Monthly Captures', MAX('Monthly Captures'[Monthly capture])
))
// this measure should be the sales status of [% Sales over 3] for the current month and it should stay fixed,
and not respond to the [Monthly capture] filter.

The goal is to calculate how many people have sold 3 or more items in the current month snapshot of the data ( max( [Monthly capture]) ), and compare this status over any existing monthly snapshot.

This means that I need to create a system where I can have a table with Month and Year of [Latest Sales Date], the [% Sales over 3] for the Current Month (i.e. [% Sales Current Month] - this needs to be unresponsive to the [Monthly capture] filter), another measure (called [% Selected Monthly Capture] that responds to whatever month is selected in the [Monthly capture] filter, and a measure that is the difference ([% Difference]) between [% Sales Current Month] and [% Selected Monthly Capture] taking into consideration that, if data is missing in the [Latest Sales Date], it will not yield a result, but it will be 0 (meaning that, if, for instance, the [% Sales Current Month]  = 86% for the month of May in [Latest Sales Date] and [% Selected Monthly Capture] is null for [Latest Sales Date] when selecting, for example, April in [Monthly capture], [% Difference] will not be 86% but 0, because there is nothing to compare between May and April.

Hope that makes sense and someone has an idea.

Many thanks!

1 ACCEPTED SOLUTION

Many thanks for your thought on this, Carson.
the formula that contains the All function will not work, because it cancels all filters:

Chris2016_0-1716376453050.png

The way I've solved this is by having another table that has only the Current status, with all the current measures:

# Current Sales People = DISTINCTCOUNT('Current Status'[Sales Person])
# Current Sales People with over 3 items sold =
  COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
        FILTER ( 'Current Status',  'Current Status'[# of Items sold]>=3),
    "@result", 'Current Status'[Sales Person])
     )
    )
% Current Sales over 3 =
IFERROR( DIVIDE([# Current Sales People with over 3 items sold], [# Current Sales People], 0),0)

In the Monthly captures table, i added a measure to allow for the selection of any month to see the comarison with the current status:

% Selected Monthly Capture (Sales over 3) =
var result = CALCULATE (
    [% Sales over 3],
 FILTER('Monthly Captures',
'Monthly Captures'[Monthly capture] = SELECTEDVALUE('Monthly Captures'[Monthly capture] )))
 return IF(ISFILTERED('Monthly Captures'[Monthly capture]),
    IF(HASONEVALUE('Monthly Captures'[Monthly capture]), result), BLANK())

Then, the difference between any month and Current:
-Difference = [% Current Sales over 3]-[% Selected Monthly Capture (Sales over 3)]
 I am also using a Calendar table where Date has a relationship with Latest Sales Date in both Monthly Captures and Current Status table, and Latest Sales Month (in the snippit below) is the Month-Year format of Calendar Date.
Chris2016_1-1716377542370.pngChris2016_2-1716377572470.png

 

There may be a better way where a Current Status table is not needed, but I did not find it yet 🙂

Many thanks for your assistence!

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi,@Chris2016 
I am glad to help you.

According to your description, you would like to calculate the percentage of salespeople with sales quantity greater than or equal to 3 recorded in different month snapshots. And you can compare any selected month's data with the most recent month's data.

Here are the results of my tests, hopefully they will help you .

 

 

# Sales Person = DISTINCTCOUNT('Monthly Captures'[Sales Person])
# Sales People with over 3 items sold = 
  COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
        FILTER ( 'Monthly Captures',  'Monthly Captures'[# of Items sold]>=3),
    "@result", 'Monthly Captures'[Sales Person])
     )
    )
% Sales over 3 = 
IFERROR( DIVIDE([# Sales People with over 3 items sold], [# Sales Person], 0),0)

 

 

I created the following measures based on my understanding.

% Sales Current Month unaffected by the [Monthly capture] slicer

 

 

% Sales Current Month = 
CALCULATE (
    [% Sales over 3],
    FILTER(
    ALL('Monthly Captures'),
    'Monthly Captures'[Monthly capture] = MAX('Monthly Captures'[Monthly capture])
    )
)

 

 

% Selected Monthly Capture affected by the [Monthly capture] slicer

 

 

% Selected Monthly Capture = 
CALCULATE (
    [% Sales over 3],
    FILTER(
    ALLSELECTED('Monthly Captures'[Monthly capture]),
    'Monthly Captures'[Monthly capture] = MAX('Monthly Captures'[Monthly capture])
    )
)

 

 

the final result “% Difference”:

 

 

% Difference = 
IF(
    ISBLANK([% Selected Monthly Capture]),
    0,
    [% Selected Monthly Capture]-[% Sales Current Month] 
)

 

 

The above is the code I created based on your description, if my understanding is wrong, please let me know in time, and I will try my best to help you .

Here is the result

vjtianmsft_0-1716295560028.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Many thanks for your thought on this, Carson.
the formula that contains the All function will not work, because it cancels all filters:

Chris2016_0-1716376453050.png

The way I've solved this is by having another table that has only the Current status, with all the current measures:

# Current Sales People = DISTINCTCOUNT('Current Status'[Sales Person])
# Current Sales People with over 3 items sold =
  COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
        FILTER ( 'Current Status',  'Current Status'[# of Items sold]>=3),
    "@result", 'Current Status'[Sales Person])
     )
    )
% Current Sales over 3 =
IFERROR( DIVIDE([# Current Sales People with over 3 items sold], [# Current Sales People], 0),0)

In the Monthly captures table, i added a measure to allow for the selection of any month to see the comarison with the current status:

% Selected Monthly Capture (Sales over 3) =
var result = CALCULATE (
    [% Sales over 3],
 FILTER('Monthly Captures',
'Monthly Captures'[Monthly capture] = SELECTEDVALUE('Monthly Captures'[Monthly capture] )))
 return IF(ISFILTERED('Monthly Captures'[Monthly capture]),
    IF(HASONEVALUE('Monthly Captures'[Monthly capture]), result), BLANK())

Then, the difference between any month and Current:
-Difference = [% Current Sales over 3]-[% Selected Monthly Capture (Sales over 3)]
 I am also using a Calendar table where Date has a relationship with Latest Sales Date in both Monthly Captures and Current Status table, and Latest Sales Month (in the snippit below) is the Month-Year format of Calendar Date.
Chris2016_1-1716377542370.pngChris2016_2-1716377572470.png

 

There may be a better way where a Current Status table is not needed, but I did not find it yet 🙂

Many thanks for your assistence!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.