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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
relliott
Frequent Visitor

Calculate difference between two periods while selecting one period from slicer

This question is similar to others, but I couldn't find any posts solving for the unique challenge I'm having. 

 

I have a simple sales table with Rep, Quarter, and Sales. I want the report user to be able to select a quarter via a filter and then see the difference in sales versus the prior quarter. I have a measure that is calculating the differences fine using SWITCH, however if a rep is not present in the quarter selected, they do not show up in the output. Below I am showing small set of sample data, the expected output, and the output I am getting along with the measure i created to calculate the delta. Can someone please help me solve to make sure all line items show up? 

 

Measure to calculate difference: 

 

Delta =
SWITCH(
SELECTEDVALUE(Sales[Quarter]),
"Q2", BLANK(),
"Q3", CALCULATE(SUM(Sales[Sales]),Sales[Quarter]="Q3")-CALCULATE(SUM(Sales[Sales]),Sales[Quarter]="Q2"),
BLANK()
)
 
Sales Table Sample Data
 
sampledatatable.PNG
 
 

Desired Output when user selects Q3 from slicer

 

desiredoutput.PNG

 

 

Actual Output I'm seeing where Joe does not show up:

 

incorrectoutput.PNG

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @relliott ,


Try the following calculated column and measure:

Q_ = IF(Sales[Quarter]="Q2",0,1)
M1 = 
VAR A =
    CALCULATE (
        MIN ( Sales[Sales] ),
        FILTER ( ALL ( Sales ), MAX ( Sales[Q_] ) = 0 )
    )
VAR B =
    CALCULATE (
        MAX ( Sales[Sales] ),
        FILTER ( ALL ( Sales ), MAX ( Sales[Q_] ) = 1 )
    )
RETURN
    CALCULATE ( B - A, FILTER ( ALL ( Sales ), MAX ( Sales[Rep] ) = Sales[Rep] ) )


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

View solution in original post

1 REPLY 1
v-henryk-mstf
Community Support
Community Support

Hi @relliott ,


Try the following calculated column and measure:

Q_ = IF(Sales[Quarter]="Q2",0,1)
M1 = 
VAR A =
    CALCULATE (
        MIN ( Sales[Sales] ),
        FILTER ( ALL ( Sales ), MAX ( Sales[Q_] ) = 0 )
    )
VAR B =
    CALCULATE (
        MAX ( Sales[Sales] ),
        FILTER ( ALL ( Sales ), MAX ( Sales[Q_] ) = 1 )
    )
RETURN
    CALCULATE ( B - A, FILTER ( ALL ( Sales ), MAX ( Sales[Rep] ) = Sales[Rep] ) )


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors