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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anthony007
Helper I
Helper I

DATEADD combined with filter function

Need help in building a report. it is necessary to show the number of orders for a similar period.

 

Using CALCULATE formula (COUNTROWS (Sheet1); DATEADD (Sheet1 [date]; - 7; DAY)) report obtained over a period of 7 days.

But what if the user selects a date with the help of the filter?

 

I used a new measure that would count the number of days in the period: CountDay = DATEDIFF (MIN (Sheet1 [date]); MAX (Sheet1 [date]); DAY).

 

Result inserted in the formula for the same period of recovery: SamePerVar2 = CALCULATE (COUNTROWS (Sheet1); DATEADD (Sheet1 [date]; - 'Sheet1' [CountDay] -1; DAY)).


As a result, I realized that in this measure there are always zero days.
Help improve the formula.

Thank you.

pbx here: https://drive.google.com/file/d/1J1VUyJ2SMdHu9LZ_VrvR4SA3Gyy_Re23/view?usp=sharing

1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anthony007,

Based on my test, you could refer to below steps:

1.Create a calender table and create relationship with your row table:

1.PNG2.PNG

2.Create two measures:

CountDay2 = VALUE(DATEDIFF (MIN ('Table'[Date]), MAX ('Table'[Date]), DAY))
Measure = CALCULATE(COUNT(Sheet1[id]),DATEADD('Table'[Date],[CountDay2],DAY))

3.Use the calender data column as the slicer,

3.PNG

 

Result:

4.PNG

You could also download the pbix file to have a view:

https://www.dropbox.com/s/3lkmj2bqmt8psle/DATEADD%20combined%20with%20filter%20function.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anthony007,

Based on my test, you could refer to below steps:

1.Create a calender table and create relationship with your row table:

1.PNG2.PNG

2.Create two measures:

CountDay2 = VALUE(DATEDIFF (MIN ('Table'[Date]), MAX ('Table'[Date]), DAY))
Measure = CALCULATE(COUNT(Sheet1[id]),DATEADD('Table'[Date],[CountDay2],DAY))

3.Use the calender data column as the slicer,

3.PNG

 

Result:

4.PNG

You could also download the pbix file to have a view:

https://www.dropbox.com/s/3lkmj2bqmt8psle/DATEADD%20combined%20with%20filter%20function.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Many thanks for the response and help.

Creating a calendar table and relationships really helps in counting the number of days in a period. But at the same time, the date hierarchy is lost and the graph displays information in the wrong way:Screenshot_5.png

 

 

And the result is the following:Screenshot_6.pngAs if to compare this period with a similar one.

 

Perhaps there is another way to count the number of days in a period without creating a date table? Or try creating a date hierarchy manually?

 

I'm now trying to write a formula that simply considers the number of unique values ​​in the date column using DISTINCTCOUNT

 

 

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