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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Hipnobe
Regular Visitor

How to disclose a sum only when the filter context is included between 2 dates

Dear Community,

 

I allow myself to post here because it has been 2 days i'm trying to find how to fix my issue but I'm getting nuts.

 

In a nutshell, I would like to create a measure that calculates the sum of the "Estimated Sales" for all business opportunities (in the 'tbl_opportunities' table) and to to show the sum for all the opportunities in the matrix only if the current date ( tbl_Date[Date] ) is included between the creation date ( tbl_opportunity[Created On] ) and the closing date ( tbl_opportunity[Closing Date] )of each opportunity.
I have tried the following formula but still, the opportunities show off after the tbl_opportunity[Closing Date]:

Open Opportunity =
VAR DateMax =
    MAX ( tbl_date[Date] )
RETURN
    SUMX (
        tbl_opportunity,
        VAR Result =
            CALCULATE ( SUM ( tbl_opportunity[Estimated value] ), ALL ( tbl_date ) )
        RETURN
            IF (
                DateMax >= tbl_opportunity[Created On]
                    && DateMax <= tbl_opportunity[Closing Date],
                Result
            )
    )

My aim would be to get a table that looks like this:

Hipnobe_0-1682011029119.png

 

and here is a look of the 2 tables involved:

Hipnobe_1-1682011164959.png

 

Any help is mora than welcome.

 

Many thanks in advance folk!
 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @Hipnobe 

According to your description, you want to "How to disclose a sum only when the filter context is included between 2 dates".

For your need , you do not need to create any relationship between your table and your date table.

vyueyunzhmsft_0-1682309092144.png

This is my test data:

vyueyunzhmsft_1-1682309115785.png

We can create a measure like this:

Measure = var _created_date =YEAR(  MAX('tbl_opportunity'[Created On])) *100 +MONTH(  MAX('tbl_opportunity'[Created On]))
var _close_date =YEAR( MAX('tbl_opportunity'[Closing Date])) *100 +MONTH( MAX('tbl_opportunity'[Closing Date])) 
var _value = SUM('tbl_opportunity'[Estimated value])
var _cur_date =YEAR( MIN('tbl_date'[Date])) *100 +MONTH( MIN('tbl_date'[Date]))
return 
IF(_close_date>= _cur_date &&  _created_date<= _cur_date ,_value ,BLANK())

Then we can put this measure on the visual and we can meet your need:

vyueyunzhmsft_2-1682309159387.png

 

 

 

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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-yueyunzh-msft
Community Support
Community Support

Hi , @Hipnobe 

According to your description, you want to "How to disclose a sum only when the filter context is included between 2 dates".

For your need , you do not need to create any relationship between your table and your date table.

vyueyunzhmsft_0-1682309092144.png

This is my test data:

vyueyunzhmsft_1-1682309115785.png

We can create a measure like this:

Measure = var _created_date =YEAR(  MAX('tbl_opportunity'[Created On])) *100 +MONTH(  MAX('tbl_opportunity'[Created On]))
var _close_date =YEAR( MAX('tbl_opportunity'[Closing Date])) *100 +MONTH( MAX('tbl_opportunity'[Closing Date])) 
var _value = SUM('tbl_opportunity'[Estimated value])
var _cur_date =YEAR( MIN('tbl_date'[Date])) *100 +MONTH( MIN('tbl_date'[Date]))
return 
IF(_close_date>= _cur_date &&  _created_date<= _cur_date ,_value ,BLANK())

Then we can put this measure on the visual and we can meet your need:

vyueyunzhmsft_2-1682309159387.png

 

 

 

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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