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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jfdacovich2022
Regular Visitor

Using a Slicer to filter by operation result between to specific dates

Hi ! We are trying to solve a problem with power bi but we are kinda blocked. Do you know how we can solve the following example being it using Dax, or with another method.

We have a set of identifiers with one value per day and we want to calculate dynamically, by selecting two dates as filter, a mathematical operation between the value for both dates for each of the components.

 

Example

 

Component 1  -  date 1 - value 1

Component 2  -  date 1 - value 2

Component 3  -  date 1 - value 3

Component 1  -  date 2 - value 4

Component 2  -  date 2 - value 5

Component 3  -  date 2 - value 6

Component 1  -  date 3 - value 7

Component 2  -  date 3 - value 8

Component 3  -  date 3 - value 9

Component 1  -  date 4 - value 10

Component 2  -  date 4 - value 11

Component 3  -  date 4 - value 12

 

We select as filters date 2 and date 4 getting

 

Component id  - date a - date b - value date a - value date b - operation

Component 1  -  date 2 - date 4 - value 4         - value 10       - (value 4 + value 10)

Component 2  -  date 2 - date 4 - value 5         - value 11       - (value 5 + value 11)

Component 3  -  date 2 - date 4 - value 6         - value 12       - (value 6 + value 12)

 

We need to do this as we need to filter the dashboard for the components where the operation results meet certain criteria between the specific dates.


Thanks in advance!! 

2 REPLIES 2
Duia
Resolver II
Resolver II

Hi  @jfdacovich2022 ,

I created some data:

Duia_0-1660129985124.png

Here are the steps you can follow:

1. Create measure.

Measure =
var _mindate=
MINX(ALLSELECTED('Table'),[Date])
var _maxdate=
MAXX(ALLSELECTED('Table'),[Date])
return
SUMX(FILTER(ALL('Table'),
'Table'[Date]=_mindate&&'Table'[Component]=MAX('Table'[Component])),[value])
+
SUMX(FILTER(ALL('Table'),
'Table'[Date]=_maxdate&&'Table'[Component]=MAX('Table'[Component])),[value])

2. Result:

Duia_1-1660129985125.png

 

Best Regards,

Liu Yang

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

daXtreme
Solution Sage
Solution Sage

daXtreme_0-1659905377826.png

daXtreme_2-1659906185968.png

Operation = 
var DateASelected = SELECTEDVALUE('Dates A'[Date A] )
var DateBSelected = SELECTEDVALUE('Dates B'[Date B] )
var ShouldCalculate = DateASelected <> DateBSelected
var Result =
    if( ShouldCalculate,
        sumx(
            distinct( Components[Component] ),
            var DateAValue =
                CALCULATE(
                    SELECTEDVALUE( Components[Value] ),
                    Components[Date] = DateASelected
                )
            var DateBValue =
                CALCULATE
                    SELECTEDVALUE( Components[Value] ),
                    Components[Date] = DateBSelected
                )
            var ShouldCalculate = 
                not ( isblank( DateAValue ) || ISBLANK( DateBValue ) )
            var Output = 
                if( ShouldCalculate, DateBValue + DateAValue )
            return
                Output
        )
    )
return
    Result

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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