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
dinovic
Frequent Visitor

Elegant formula to calculate past 14 days and compare same period previous month

The following formula calculates Total Sessions last 14 days (dynamic for the last date).



 

Total Sessions last 14 days = CALCULATE(SUM('Table1'[Total Sessions]),
	DATESBETWEEN('Table1'[Date],
		DATEADD(LASTDATE('Table1'[Date]),-13,DAY),
		LASTDATE('Table1'[Date])))

So, my assumption is that the current day is inclusive and thus including the past 13 days, in addition to the current, would yield me a measure of the last 14 days.

Measuring the Total Sessions with one-month lag I use the following formula

1 month back total sessions = CALCULATE(SUM('Table1'[Total Sessions]),
	DATESBETWEEN('Table1'[Date],
		DATEADD(LASTDATE('Table1'[Date]),-44,day),
		DATEADD(LASTDATE('Table'[Date]),-31,DAY)
))


If my understanding is correct of the formula above, it should return the Total Sessions over 14 days, lagged with 31 days from the current date.

Is there perhaps a more elegant solution, to calculating a period of 2 weeks dynamic from the last date in the dataset, compared to the same 2 weeks period but with a one-month lag?

Thanks

 

2 REPLIES 2
dinovic
Frequent Visitor

Any ideas :)?

Vvelarde
Community Champion
Community Champion

@dinovic

 

 

Measure 1onePrev =
VAR Month_1=DATEADD(LASTDATE(Table1[Date]);-1;MONTH)
RETURN
CALCULATE(SUM(Table1[Value]);DATESBETWEEN(Table1[Date];Month_1-13;Month_1))




Lima - Peru

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.