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

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

Reply
PBIX1234
Frequent Visitor

Measure with multiple dates & an exception

Hi, I am working with a model that has two fact tables joined by some shared dimensions.

 

The fact tables are our payments named SPEND (top left) and contract records named CONTRACTS (bottom right)

 

They are joined by Date & Supplier that are common, as well as Categories which has some mapping.

 

Screenshot of the model;

Screenshot 2023-03-30 162626.png

 

I am trying to create a measure for Contracted Spend. The conditions are;

Contracted Amount = 

Sum of SPEND(Amount)

 

Occurs after CONTRACTS(Start)

AND

Occurs before CONTRACTS(End) ... *UNLESS the CONTRACTS(Status) is "Active"

 

*The last condition is to account for contracts that are expired but rolling on terms - this is how our system tracks it.

 

I tried first getting the result excluding the exception of active contracts after expiry, but still didn't get the desired result;

 

Contracted Amount =
    CALCULATE(
                SUM(SPEND[AMOUNT]),
                CONTRACTS[START]<MAX('DATE'[Date]),
                CONTRACTS[END]>MAX('DATE'[Date]),
     )
 

How would this formula be phrased?

 
 
Many thanks!

 

 

6 REPLIES 6
tamerj1
Super User
Super User

Hi @PBIX1234 
How does your report look like?

Hi @tamerj1 ,

Here is a sample file.

@PBIX1234 
What should be the result?

@tamerj1 , technically the result on the sample file is correct, all should be "contracted". However, it is not calculating correctly, as the current measures don't account for "if active after expiry date". Hence, 2021 should show as unconctracted without the exception. 

I started a new measure called "Contracted Amount (2)" to compare with - this is what I need the formula help with.

Thank you 🙂

@PBIX1234 
Please check this measure and let me know if this is what you want.

Contracted Amount (2) = 
SUMX (
    ALL ( CONTRACTS ),
    SUMX ( 
        FILTER ( 
            SPEND,
            SPEND[NAME] = CONTRACTS[NAME]
                && SPEND[DATE] >= CONTRACTS[START]
                && OR ( 
                    SPEND[DATE] <= COALESCE ( CONTRACTS[EXPIRY], TODAY ( ) ),
                    CONTRACTS[STATUS] = "Active"
                )
        ),
        SPEND[AMOUNT]
    )
)

@tamerj1 ,

 

Thank you - it did return the correct result but when I tested another sample dataset it was not correct. I am also concerned about using ALL(Contracts), as this will remove the ability to filter by Category later down the track for example.

 

I have a new sample dataset here, it may be clearer. Can you please perhaps have another look?

 

Appreciate your help!

 

Thanks 🙂

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.