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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
subhashg
Frequent Visitor

DatesInPeriod with duplicate dates in fact table Unique in Calender table

Unable to get 3M rolling sum using datesInPeriod inspite of calender marked as date table.

I have 2 tables.

Fact table(Table)- Duplicate date keys,

Calender table - Unique keys & marked as date table

Relationship - 1(Calender) to Many(Fact table)

Below is the data . 

Fact table : 

Table
Item numberQtyFact date
121451-Mar-23
131451-Apr-23
141301-May-23
151401-May-23
161501-Jul-23
121451-Aug-23
 

 

Calender table:

Calender
Date
1-Mar-23
2-Mar-23
3-Mar-23
4-Mar-23
5-Mar-23
6-Mar-23
7-Mar-23
8-Mar-23
9-Mar-23
10-Mar-23
11-Mar-23

 

 

Both below dax not giving the right 2M rolling sum. It is not summing up based on dates filter.

3M DatesInPeriod =
CALCULATE(sum('Table'[Qty]),DATESINPERIOD('Calender'[Date],max('Table'[Fact date]),-2,MONTH))

 

3m DatesBetween =
VAR _FDate= EDATE(max('Table'[Fact date]),-1)
VAR _LDate=max('Table'[Fact date])
Return
CALCULATE(sum('Table'[Qty]),DATESBETWEEN('Calender'[Date],_FDate,_LDate))

Result :

subhashg_2-1694150258959.png

 

 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @subhashg ,

 

The reason it is showing incorrect figures is because the formula is referencing the fact table date column instead of the calendar table.   It is recommended that we always use fields from a dimension table in our visualization instead of the fact table in order to avoid unintentional issues like this.  Modifying your dax formula to reference the calendar table date instead of the fact table date produces the following output for datesbetween.  

Sakiko_0-1694157426664.png

Also, for datesinperiod, the same output was produced.

Sakiko_1-1694157539607.png

I attach the pbix file for your reference:

DatesInPeriod task.pbix

View solution in original post

1 REPLY 1
DataNinja777
Super User
Super User

Hi @subhashg ,

 

The reason it is showing incorrect figures is because the formula is referencing the fact table date column instead of the calendar table.   It is recommended that we always use fields from a dimension table in our visualization instead of the fact table in order to avoid unintentional issues like this.  Modifying your dax formula to reference the calendar table date instead of the fact table date produces the following output for datesbetween.  

Sakiko_0-1694157426664.png

Also, for datesinperiod, the same output was produced.

Sakiko_1-1694157539607.png

I attach the pbix file for your reference:

DatesInPeriod task.pbix

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors