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
Arkhos94
Helper IV
Helper IV

calculate measure between max date and max date -28

I have a database with the orders my company receive, with one line per order and one column with the date of each order

 

I want to calculate the number of order per 4 rolling week, starting from the last order (so with a date between the maximum order[date] and the maximum order[date] minus 28 days)

 

First I tried to create a measure :

OrderRolling = calculate (sum(order[Number of unit ordered]),order[date]<=max(order[date]),order[date]>=max(order[date])-28)

 

It did not work (the measure refuse to let me use max as a filter value of my calculate)

 

I try to get arround it by created a measure called lastorder (lastorder=max(order[date])) and put it instead of max(order[date]) in OrderRolling measure but it did not work either

 

Then I tried to find a way to create in power query a new column that will be Ok if the Date column is between max(order[date]) and max(order[date]) - 28 days but I coudn't find the correct function

 

Any help now would be welcome

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Arkhos94 

You can use DATESINPERIOD DAX to count the number between max date and max date-28 .Use date column to create a slicer and then create a measure .

Measure = CALCULATE(COUNTROWS('Table'),DATESINPERIOD('Table'[Date],MAX('Table'[Date]),-28,DAY))

Original data:

Ailsa-msft_0-1620891388428.png

The effect is as shown :

Ailsa-msft_1-1620891388431.png

Best Regards

Community Support Team _ Ailsa Tao

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @Arkhos94 

You can use DATESINPERIOD DAX to count the number between max date and max date-28 .Use date column to create a slicer and then create a measure .

Measure = CALCULATE(COUNTROWS('Table'),DATESINPERIOD('Table'[Date],MAX('Table'[Date]),-28,DAY))

Original data:

Ailsa-msft_0-1620891388428.png

The effect is as shown :

Ailsa-msft_1-1620891388431.png

Best Regards

Community Support Team _ Ailsa Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi, @Arkhos94 

Please check the below picture and the sample pbix file's link down below.

I tried to create the sample pbix file based on the explanation.

I suggest having a DimDate table like below. Then time intelligence calculation will become much more easy.

 

Picture1.png

Orders Count 28 days rolling =
SUMX (
DATESINPERIOD ( DimDate[Date], LASTDATE ( DimDate[Date] ), -28, DAY ),
[Order Count]
)
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
PaulDBrown
Community Champion
Community Champion

@Arkhos94 

1) Create a calendar table using the CALENDARAUTO. Let's call this table Calendar Table. In the modeling view, Link the Calendar [Date] field to your Order[Date] field in a One-to-many relationship.

2) Create the measure:

OrderRolling =
CALCULATE (
    SUM ( order[Number of unit ordered] ),
    DATESBETWEEN (
        Calendar[Date],
        MAX ( Calendar[Date] ) - 28,
        MAX ( Calendar[Date] )
    )
)

 

Set up the visual using the date field from the Calendar Table and add the measure.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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