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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gustavo468
Frequent Visitor

Calculate Sum with last two date Selected in Slicer

Dear All, I´m new here and I´m new with Power BI.

 

I´m making my first dashboard and I have the following problem.

 

In my dashboard, I have a Slicer with date and that slicer control the Sales ammount (Sales[Ammount]).

 

I want to get the difference between these two dates selected in this slicer no matter if this are consecutive or not.

gustavo468_0-1659741103006.png

 

Is it possible ?

 

Thanks




1 ACCEPTED SOLUTION

Hi @gustavo468 ,

You can create a measure as below to get it, please find the details in the attachment.

Difference = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
VAR _secondmdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < _maxdate )
    )
VAR _mamount =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER ( 'Table', 'Table'[Date] = _maxdate )
    )
VAR _smamount =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER ( 'Table', 'Table'[Date] = _secondmdate )
    )
RETURN
    _mamount - _smamount

yingyinr_0-1660022824836.png

If the above one is not working for you, please provide some sample data(exclude sensitive data) with Text format and your expected result with special examples and screenshots. It is better if you can provide me a simplified pbix file. Thank you.

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
gustavo468
Frequent Visitor

@v-yiruan-msft ,that´s work for me, Thank so much !!!!!

gustavo468
Frequent Visitor

Sorry, the difference between the ammount sales for those dates. Thanks

Hi @gustavo468 ,

You can create a measure as below to get it, please find the details in the attachment.

Difference = 
VAR _maxdate =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
VAR _secondmdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < _maxdate )
    )
VAR _mamount =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER ( 'Table', 'Table'[Date] = _maxdate )
    )
VAR _smamount =
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER ( 'Table', 'Table'[Date] = _secondmdate )
    )
RETURN
    _mamount - _smamount

yingyinr_0-1660022824836.png

If the above one is not working for you, please provide some sample data(exclude sensitive data) with Text format and your expected result with special examples and screenshots. It is better if you can provide me a simplified pbix file. Thank you.

Best Regards

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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