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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jayrx7
Frequent Visitor

DATESINPERIOD not counting the days in previous year

Hello, Power BI Newbie here,

 

I am trying to create a measure that counts the rows of the rolling 365 days' record:

 

Below is my DAX:

 

24HR (Avg) =
 CALCULATE(COUNTROWS('CFS'), DATESINPERIOD('CFS'[DATES to USE], MAX('CFS'[DATES to USE]), -365, DAY))
 
However, it seems like the measure is only counting the rows from 1/1/2022 to MAX('CFS'[DATES to USE]), and not going all the way back to 9/15/2021. But when i do something like -7, or - whatever that doesn't exceed the number of days from 1/1/2022 to today it works fine. But anything exceeds that only gives me the year to date count.
 
My CFS table has data from 1/1/2021 to today.

 

Thank you in advance!

1 ACCEPTED SOLUTION

Hi Tom,

 

I went back and check my data and realized I only pulled 2021's data from 1/1/2021 to 9/14/2021. I fixed my query and pulled the whole year's data and now the solution works.

 

Thank you so much!

View solution in original post

4 REPLIES 4
TomMartens
Super User
Super User

Hey @Jayrx7 ;

 

please try this statement:

CALCULATE(COUNTROWS('CFS'), DATESINPERIOD('CFS'[DATES to USE], CALCULATE(MAX('CFS'[DATES to USE])), -365, DAY))


Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thank you Tom.

 

I tried your solution, but it is giving me the same output as what I had. It doesn't go past 1/1/2022 into 2021's data somehow.

Hey @Jayrx7 ,

 

please create a pbix file that contains sample data but still reflects your data model (tables, calculated columns, relationships, and measures). Upload the pbix to onedrive, google drive, or dropbox and share the link. If you are using Excel to create the sample data instead of the manual input method share the Excel file as well.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,

 

I went back and check my data and realized I only pulled 2021's data from 1/1/2021 to 9/14/2021. I fixed my query and pulled the whole year's data and now the solution works.

 

Thank you so much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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