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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.