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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
JayJayOliveira
New Member

Exclude conflicting dates in date difference calculation

Hello everyone!

I'm having trouble excluding date values that are between "bigger" intervals.
Can someone please help? 🙂

I find it better to explain through an example (will use integer values to explain better, but the intention is to do this with dates):

FROM            TO              DIFF
1                    3                 2
4                    10               6
5                    6                 1
6                    11               5

The values 5,6 and 10 (from the FROM and TO columns) are between the inverval [4,11]

What I want to be able to do is to calculate the SUM from the unconflicted intervals [1,3] and [4,11].

Is this possible to do?

Thank you!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@JayJayOliveira , Please find the file where I have created an overlapping flag

You need create an index column or make join only > or <

Try like

future conflict = if(ISBLANK( COUNTX(FILTER(Sheet1,  EARLIER([from Date]) >= [from Date] && EARLIER(Sheet1[from Date])<=([to Date]) && [Index] <> EARLIER([Index])),[from  Date])),"NoConflict","Conflict")

 or

future conflict = if(ISBLANK( COUNTX(FILTER(Sheet1,  EARLIER([from Date]) > [from Date] && EARLIER(Sheet1[from Date])<([to Date]) ),[from  Date])),"NoConflict","Conflict")
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

HI @JayJayOliveira,

Based on my test, I found it is recursive calculation related requirements that dax formula not able to achieve. (power bi does not contain row/column index, if you want to use previous calculation result, you need to manually write formulas and setting filter conditions as previous row contents)

Recursion in DAX 

For example, below is a calculated column formula that I used to check related records and expand the range:

RelatedRange = 
VAR temp =
    FILTER (
        'Sample',
        COUNTROWS (
            INTERSECT (
                GENERATESERIES ( [Start], [End] ),
                GENERATESERIES ( EARLIER ( 'Sample'[Start] ), EARLIER ( 'Sample'[End] ) )
            )
        ) > 0
    )
VAR rStart =
    MINX ( temp, [Start] )
VAR rEnd =
    MAXX ( temp, [End] )
RETURN
    rStart & "~" & rEnd

10.png

It works properly but you can find it still not getting the 'final' expand ranges, you need to calculation on the result of above calculation column with the same logic and duplicate these operations until no intersect range existed. (this is the real range your formula need to be calculated)

I'd like to suggest you do these in query editor which support recursive. (recursive calculate custom function will reduce the processing performance and cost huge amount of resource)

Recursive Functions in Power BI / Power Query 

Regards,

Xiaoxin Sheng

amitchandak
Super User
Super User

@JayJayOliveira , Please find the file where I have created an overlapping flag

You need create an index column or make join only > or <

Try like

future conflict = if(ISBLANK( COUNTX(FILTER(Sheet1,  EARLIER([from Date]) >= [from Date] && EARLIER(Sheet1[from Date])<=([to Date]) && [Index] <> EARLIER([Index])),[from  Date])),"NoConflict","Conflict")

 or

future conflict = if(ISBLANK( COUNTX(FILTER(Sheet1,  EARLIER([from Date]) > [from Date] && EARLIER(Sheet1[from Date])<([to Date]) ),[from  Date])),"NoConflict","Conflict")
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

hey @amitchandak ! Thanks for your response, it worked perfectly on many cases.

But on this one specifically we have an issue. Because of a 30 day conflict it is descarding the 2.9 value.

Annotation 2020-05-14 161718.png
I wonder if we could just discard the 30 day conflict?

@JayJayOliveira , Can you share a better data with expected output

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.

Top Solution Authors