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
bvbull200
Helper III
Helper III

Analyzing 3 Months Before/After a Date w/Date Being Different For Different Rows

I have two data tables.  The first is a list of part #s with each transaction against them over the past 18 months.  Each part # is listed multiple times due to being transacted against on multiple occasions.  I have the date of each transaction.

 

The second is a list of each of those part #s with a modified date.  Each part # is listed once and the modified date indicates when a particular enhancement went in to place.  Each part was modified on a different date.

 

What I need to do is sum all of the transactions for each part for the 3 months prior to the modification date and the 3 months after the modification date.

 

For instance, if a part was modified on 07/01/2019, I would need to know the sum of transactions from 04/01/2019 - 06/30/2019 and separately, the sum of transactions from 07/01/2019 - 09/30/2019.

 

For a different part, it might have been modified on 09/16/2019.  I would need to know the sum of transactions from 06/16/2019 - 09/15/2019 and separately, the sum of transactions from 09/16/2019 - 12/15/2019.

 

Ideally, I would be able to have that 3 month before/after be a dynamic number that I can select via a slider or something, so if I wanted to look at 6 months before/after, I could do that on the fly.  If it is static and has to be changed via the measure, that is okay, too.

 

Here is a sample of data to work with.  I appreciate any bright ideas to help solve this.

 

Transaction Table

Part #TransactionValueTransaction Date
Umbrella1501/1/2019
Umbrella1501/1/2019
Umbrella751/1/2019
Umbrella751/1/2019
Umbrella66.972/1/2019
Umbrella3782/1/2019
Umbrella139.12/1/2019
Umbrella70.52/1/2019
Umbrella753/1/2019
Umbrella72.734/1/2019
Umbrella251.924/1/2019
Umbrella67.54/1/2019
Umbrella754/1/2019
Umbrella6934/1/2019
Umbrella1265/1/2019
Umbrella66.155/1/2019
Umbrella1265/1/2019
Umbrella251.928/1/2019
Umbrella67.58/1/2019
Umbrella758/1/2019
Umbrella6938/1/2019
Umbrella1269/1/2019
Umbrella66.159/1/2019
Umbrella1269/1/2019
Umbrella251.929/1/2019
Umbrella67.59/1/2019
Umbrella759/1/2019
Umbrella69310/1/2019
Umbrella12610/1/2019
Umbrella66.1510/1/2019
Umbrella12610/1/2019
Umbrella251.9210/1/2019
Umbrella67.510/1/2019
Umbrella7511/1/2019
Umbrella69311/1/2019
Umbrella12611/1/2019
Umbrella66.1511/1/2019
Umbrella12611/1/2019
Umbrella251.9211/1/2019
Umbrella67.511/1/2019
Umbrella7512/1/2019
Umbrella69312/1/2019
Umbrella12612/1/2019
Umbrella66.1512/1/2019
Umbrella12612/1/2019
Umbrella251.9212/1/2019
Umbrella67.512/1/2019
Umbrella7512/1/2019
Umbrella69312/1/2019
Toaster79.281/1/2019
Toaster1004.851/1/2019
Toaster134.572/1/2019
Toaster90.852/1/2019
Toaster183.62/1/2019
Toaster69.732/1/2019
Toaster82.912/1/2019
Toaster79.132/1/2019
Toaster61.253/1/2019
Toaster151.964/1/2019
Toaster102.684/1/2019
Toaster370.324/1/2019
Toaster112.95/1/2019
Toaster153.855/1/2019
Toaster575.885/1/2019
Toaster72.295/1/2019
Toaster154.355/1/2019
Toaster734.586/1/2019
Toaster1022.878/1/2019
Toaster376.878/1/2019
Toaster144.48/1/2019
Toaster318.179/1/2019
Toaster69.239/1/2019
Toaster61.359/1/2019
Toaster184.219/1/2019
Toaster330.029/1/2019
Toaster111.689/1/2019
Toaster48.0210/1/2019
Toaster273.0810/1/2019
Toaster139.6610/1/2019
Toaster60.8310/1/2019
Toaster991.6810/1/2019
Toaster80.1910/1/2019
Toaster327.2411/1/2019
Toaster118.1911/1/2019
Toaster1004.8511/1/2019
Toaster65.3611/1/2019
Toaster76.1411/1/2019
Toaster5411/1/2019
Toaster51.5711/1/2019
Toaster75.1511/1/2019
Toaster91.3511/1/2019
Toaster90.3211/1/2019
Toaster550.7511/1/2019
Toaster161.712/1/2019
Toaster180.0512/1/2019
Toaster111.612/1/2019
Toaster59.0612/1/2019
Toaster87.912/1/2019

 

Modified Date Table

PartModified Date
Umbrella8/1/2019
Toaster4/1/2019
1 ACCEPTED SOLUTION

@bvbull200, Try

Measure = calculate(sum(Transaction[TransactionValue]),all('Modified Date Table'), 
		filter(Transaction, 
			Transaction[Transaction date]>= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date],-3,Month))	
			&& Transaction[Transaction date]<= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date],3,Month))
			
			)
)

OR
Rolling 6 from -3= CALCULATE(sum(Transaction[TransactionValue]),DATESINPERIOD('Modified Date Table'[Date],ENDOFMONTH(dateadd('Modified Date Table'[Date],-3,MONTH)),6,MONTH))  

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

When data is grouped at part level, this can help

 

calculate(sum(Transaction[TransactionValue]),all('Modified Date Table'), 
		filter(Transaction, Transaction[Transaction date]>= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date]),-3,Month)	
			&& Transaction[Transaction date]<= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date]),3,Month)))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Hmmm...I'm running in to a number of errors with that.  At first it was syntax, but I have fixed that.  Now it is saying that there are too few variables for DateAdd.

 

I'll keep tinkering with it.

Share you current formula

Measure = calculate(sum(Transaction[TransactionValue]),all('Modified Date Table'), 
		filter(Transaction, Transaction[Transaction date]>= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date]),-3,Month)	
			&& Transaction[Transaction date]<= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date]),3,Month)))

The error is:

 

Too few arguments were passed to the DATEADD function. The minimum argument count for the function is 3.

@bvbull200, Try

Measure = calculate(sum(Transaction[TransactionValue]),all('Modified Date Table'), 
		filter(Transaction, 
			Transaction[Transaction date]>= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date],-3,Month))	
			&& Transaction[Transaction date]<= minx('Modified Date Table',dateadd('Modified Date Table'[Modified Date],3,Month))
			
			)
)

OR
Rolling 6 from -3= CALCULATE(sum(Transaction[TransactionValue]),DATESINPERIOD('Modified Date Table'[Date],ENDOFMONTH(dateadd('Modified Date Table'[Date],-3,MONTH)),6,MONTH))  

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.