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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
JonV
Helper II
Helper II

DATESBETWEEN with two tables

Hi all,

I have a fact table that has start and end dates for a process. My goal is to create a calculated column in that fact table to determine the number of days in that period that were holidays.

Separately, I have a dim date table that has a column to denote whether a given date is a holiday or not.

What I thought I'd be able to do is use something along the lines of 

 

 

=COUNTROWS(
    CALCULATETABLE(
        DATESBETWEEN(
            'Date Table'[Dates], 'Fact Table'[Start Date], 'Fact Table'[End Date]), 
        'Date Table'[IsHoliday?] = TRUE
    )
)

 

 

The issue I'm running into is the DATESBETWEEN function won't accept values from the Fact Table. The relationship between the two tables is defined in the model. 

Any thoughts on why this isn't working or a better approach?

1 ACCEPTED SOLUTION


@VasTg wrote:

How is the relationship between the fact and date is defined?

It is a one-to-many relationship between the date from the date table to the start date in the fact table. 


@VasTg wrote:

Here is the sample DAX that works for me.

 

 

Column = CALCULATE(SUM('Table 2'[Holiday]),FILTER(ALL('Table 2'),'Table 2'[Date]>='Fact'[Start] &&'Table 2'[Date]<='Fact'[End]))

 

This did not work for me either as DAX is not allowing my to compare the dates from the Fact table to the Date table, I suspect for the same reason as I'm not able to use the functions I intended to.

View solution in original post

5 REPLIES 5
VasTg
Memorable Member
Memorable Member

@JonV 

 

How is the relationship between the fact and date is defined?

 

Here is the sample DAX that works for me.

 

Column = CALCULATE(SUM('Table 2'[Holiday]),FILTER(ALL('Table 2'),'Table 2'[Date]>='Fact'[Start] &&'Table 2'[Date]<='Fact'[End]))

 

Table 2 is date(Holiday is a column with value 1 as holiday and 0 is a non holiday)

Fact is your fact.

 

If this helps, mark it as a solution

Kudos are nice too

 

Connect on LinkedIn

@VasTg 

I was able to get your formula to work with a bit of modification:

Holidays in Period = 
CALCULATE(
    SUM('Date Table'[IsHoliday]),
    FILTER('Date Table',
        'Date Table'[FullDate] >='Fact Table'[Start Date] 
        && 'Date Table'[FullDate] <= 'Fact Table'[End Date]
    )
)

 


@VasTg wrote:

How is the relationship between the fact and date is defined?

It is a one-to-many relationship between the date from the date table to the start date in the fact table. 


@VasTg wrote:

Here is the sample DAX that works for me.

 

 

Column = CALCULATE(SUM('Table 2'[Holiday]),FILTER(ALL('Table 2'),'Table 2'[Date]>='Fact'[Start] &&'Table 2'[Date]<='Fact'[End]))

 

This did not work for me either as DAX is not allowing my to compare the dates from the Fact table to the Date table, I suspect for the same reason as I'm not able to use the functions I intended to.

VasTg
Memorable Member
Memorable Member

@JonV 

 

Try variables to get the start and end date from fact.

 

Attach your mockup pbix to troubleshoot.

 

If this helps, mark it as a solution

Kudos are nice too

Connect on LinkedIn

Here is a link to a sample pbix. Please let me know if that works.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.