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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Alam69
Regular Visitor

Dynamically calculate differences based on slicer slection

Hello, I have a table with Revenues of all months and I need to build a difference between two selected months.

2 ACCEPTED SOLUTIONS
v-kaiyue-msft
Community Support
Community Support

Hi @Alam69 ,

 

Thanks for the reply from @ahadkarimi , please allow me to provide another insight: 

 

You can create measure.

Diff = 
VAR _min =
    CALCULATE ( MIN ( 'financials'[Date] ), ALLSELECTED ( financials[Date] ) )
VAR _max =
    CALCULATE ( MAX ( 'financials'[Date] ), ALLSELECTED ( financials[Date] ) )
VAR _s1 =
    CALCULATE ( SUM ( 'financials'[ Sales] ), 'financials'[Date] = _min )
VAR _s2 =
    CALCULATE ( SUM ( financials[ Sales] ), 'financials'[Date] = _max )
RETURN
    _s2 - _s1

vkaiyuemsft_1-1722998962773.png

 


It is worth noting that if three and more dates are selected in the slicer, it still calculates the difference between the maximum and minimum dates.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

 

View solution in original post

v-kaiyue-msft
Community Support
Community Support

Hi @Alam69 ,

 

You can create measure.

Revenue 1. month = 
VAR _min =
    CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
VAR _sum =
    CALCULATE ( SUM ( 'Table'[Revenue] ), 'Table'[Date] = _min )
RETURN
    _sum

 

Revenue 2. month = 
VAR _max =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
VAR _sum =
    CALCULATE ( SUM ( 'Table'[Revenue] ), 'Table'[Date] = _max )
RETURN
    _sum

 

Diff = 
[Revenue 2. month] - [Revenue 1. month]

vkaiyuemsft_0-1723171976823.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

 

View solution in original post

7 REPLIES 7
v-kaiyue-msft
Community Support
Community Support

Hi @Alam69 ,

 

You can create measure.

Revenue 1. month = 
VAR _min =
    CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
VAR _sum =
    CALCULATE ( SUM ( 'Table'[Revenue] ), 'Table'[Date] = _min )
RETURN
    _sum

 

Revenue 2. month = 
VAR _max =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table'[Date] ) )
VAR _sum =
    CALCULATE ( SUM ( 'Table'[Revenue] ), 'Table'[Date] = _max )
RETURN
    _sum

 

Diff = 
[Revenue 2. month] - [Revenue 1. month]

vkaiyuemsft_0-1723171976823.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

 

Alam69
Regular Visitor

Hello, thanks again. The two months/dates will be selected in the slicer by using the control key. So it doesn't work like you presented. Notice that my data table is joined/linked with the calendar date table.

Alam69
Regular Visitor

Thank you very much. I will try to make the difference for the whole year 2024. Chokran

v-kaiyue-msft
Community Support
Community Support

Hi @Alam69 ,

 

Thanks for the reply from @ahadkarimi , please allow me to provide another insight: 

 

You can create measure.

Diff = 
VAR _min =
    CALCULATE ( MIN ( 'financials'[Date] ), ALLSELECTED ( financials[Date] ) )
VAR _max =
    CALCULATE ( MAX ( 'financials'[Date] ), ALLSELECTED ( financials[Date] ) )
VAR _s1 =
    CALCULATE ( SUM ( 'financials'[ Sales] ), 'financials'[Date] = _min )
VAR _s2 =
    CALCULATE ( SUM ( financials[ Sales] ), 'financials'[Date] = _max )
RETURN
    _s2 - _s1

vkaiyuemsft_1-1722998962773.png

 


It is worth noting that if three and more dates are selected in the slicer, it still calculates the difference between the maximum and minimum dates.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

 

ahadkarimi
Solution Specialist
Solution Specialist

Hey Alam, I suppose this is your table. Let me know if there is any problem:

MonthRevenue
January10000
February12000
March15000
April13000
May16000


Create a measure to capture the revenue for the first selected month:
SelectedMonth1Revenue =
VAR SelectedMonth1 = SELECTEDVALUE('MonthlyRevenue'[Month])
RETURN
CALCULATE(SUM('MonthlyRevenue'[Revenue]), 'MonthlyRevenue'[Month] = SelectedMonth1)

Create a measure to capture the revenue for the second selected month:
SelectedMonth2Revenue =
VAR SelectedMonth2 = SELECTEDVALUE('MonthlyRevenue'[Month])
RETURN
CALCULATE(SUM('MonthlyRevenue'[Revenue]), 'MonthlyRevenue'[Month] = SelectedMonth2)

Create a measure to calculate the difference between the two selected months:
RevenueDifference =
[SelectedMonth1Revenue] - [SelectedMonth2Revenue]

 

Hi, I adjusted my request and want to create a table in the report view like on the right.

For each month I have a table with date, deprt. and Revenue. I will import all tables via folder into Power BI.

 

DateDeprt.Revenue Slicer date Deprt.Revenue 1. monthRevenue 2. monthDiff.
01.01.2024A50 Period e.g. A3514-21
01.01.2024B60 01.02.2024 B122614
01.01.2024C55 and C28684
01.01.2024D99 01.04.2024 D5203198
01.01.2024E3   E2317-6
01.02.2024A35    77346269
01.02.2024B12       
01.02.2024C2       
01.02.2024D5       
01.02.2024E23       
01.03.2024A204       
01.03.2024B65       
01.03.2024C95       
01.03.2024D115       
01.03.2024E66       
01.04.2024A14       
01.04.2024B26       
01.04.2024C86       
01.04.2024D203       
01.04.2024E17      

 

ahadkarimi
Solution Specialist
Solution Specialist

Hey Alam,

ahadkarimi_0-1723045403166.png

You need to create 3 new measures:

First up, head to Modeling -> New Measure and create this:


Revenue 1. month =
CALCULATE(
SUM('Table'[Revenue]),
FILTER(
'Table',
'Table'[Date] = SELECTEDVALUE('SlicerTable'[Date1])
)
)

Next, go to Modeling -> New Measure again and add this:

 

Revenue 2. month =
CALCULATE(
SUM('Table'[Revenue]),
FILTER(
'Table',
'Table'[Date] = SELECTEDVALUE('SlicerTable'[Date2])
)
)

Then, go to Modeling -> New Measure again and add this:

 

Diff. = [Revenue 2. month] - [Revenue 1. month]

Lastly, add a slicer and include the Date field in it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.