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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculating days of overlap

Hello,

 

I've been trying to create DAX functions to calculate program overlapping days, but so far still unsuccessful.

What my goal is to calculate the number of days two or more program overlapped (program dates) and the dollar amount associate with the overlap.

I have a very large data table of following information:

 

Line #
Marketing Partner CodeMarketing Item CodeMarketing Program CodeProgram Start DatePrograme End DateExpense
1Company APAHola 1Jan 1 2019Jan 31 2019$500,000
2Company APAHola 2Jan 15 2019Jan 18 2019$120,000
3Company APAHola 3Jan 30 2019Feb 20 2019$95,000
4Company BPBHola 1Jan 1 2019Jan 31 2019$500,000

 

I also created a calendar table so that the user can define the program validity dates like so:

Capture.PNG

In my business what can happen is for a given marketing partner and marketing item, there can be multiple marketing campaigns that might run simultaneous (either full or partial duration) and I want to know given those overlapping days, how much additional expense we spent/day.

 

I consider overlapping days with the following logic:

  1. Concanate of Partner Code and Product code matches
  2. The start and end date of the program code of #1 somehow overlaps (3 programs overlap from above data table)
 

With those overlapping days (line 1 to 3 overlaps: 4 days + 3 days), I want to get the simple average expense/day (e.g., Company A + PB + Program 1 Marketing Expense divided by the total validity days of Program 1 of the same combination). So

 

With this information, I am going to multiply the average expense/day, days overlapping AND product volume data (which is another table)

 

Would appreciate any help or tips. Thanks in advance!

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

Hi,

 

Please try this measure:

Measure =
SUM ( 'Table'[Expense] )
    / COUNTROWS (
        FILTER (
            CALENDAR (
                MIN ( 'Table'[Program Start Date] ),
                MAX ( 'Table'[Programe End Date] )
            ),
            COUNTROWS (
                FILTER (
                    'Table',
                    'Table'[Program Start Date] <= [Date]
                        && 'Table'[Programe End Date] >= [Date]
                )
            ) >= 2
        )
    )

The result shows:

2.PNG

 

Best Regards,

Giotto Zhi

View solution in original post

4 REPLIES 4
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please try this measure:

Measure =
SUM ( 'Table'[Expense] )
    / COUNTROWS (
        FILTER (
            CALENDAR (
                MIN ( 'Table'[Program Start Date] ),
                MAX ( 'Table'[Programe End Date] )
            ),
            COUNTROWS (
                FILTER (
                    'Table',
                    'Table'[Program Start Date] <= [Date]
                        && 'Table'[Programe End Date] >= [Date]
                )
            ) >= 2
        )
    )

The result shows:

2.PNG

 

Best Regards,

Giotto Zhi

Anonymous
Not applicable

@Greg_DecklerThank you for the suggestion, but the code doesn't seem to work as intended, but this was a new DAX function that I think would be useful for my future use!

 

@v-gizhi-msftThank you so much for the suggestion. I understand the logic behind the division, but don't fully understand the first "filter" and the reason behind putting the 2nd "countrow" Could you help me understand please?

 

I have a very large data (50k+ lines) that has numerous Marketing Partner Code, Program Code, etc... Is there a way to adjust the code so that I can get the data based on the combination (concanate) of Partner Code and Marketing Item (e.g., if Partner C has a certain item with program and so does Partner G within certain length of overlapping program dates)

Also, my "date" slicer doesn't seem to interact with the data. How do I link my separate calendar table that I created?

 

 

Hi,

 

The first filter is to generate a duration date calendar, the second filter is to count the rows that the date from calendar table which is between start date and end date from another main table.

 

Best Regards,

Giotto Zhi

Greg_Deckler
Community Champion
Community Champion

I would think it would be something along the lines of:

 

Overlap Column = 
  VAR __Line = [Line]
RETURN
  COUNTROWS(
    INTERSECT(
      GENERATE([Program Start Date],[Program End Date]),
      GENERATE(
        MINX(FILTER(ALL('Table'),[Line] <> __Line),[Program Start Date]),
        MAXX(FILTER(ALL('Table'),[Line] <> __Line),[Program End Date])
      )
    )
  )

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.