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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
mansi64011
Frequent Visitor

Calculate Time to reach First $25000

Hello,

I am trying to calculate the time when a customer hits hits $25000 mark on his account.

I have the following fields:

1. Customer ID:- Uniquely defining the customer

2. Date Account Opened:- the date when the account was opened

2. Invoice date : Dates when customer places order

4. Price: Amount charged to the customer for that order

 

Table looks like below:

Customer IDDate Account OpenedInvoice DatePrice
1118/3/20179/4/2017 $            3,424
6273/5/20184/4/2018 $              10,000
1118/3/20175/2/2018 $              15,892
3396/9/20178/10/2017 $              17,029
3396/9/20172/4/2019 $                 8,712

 

How should I do this in DAX?

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

 

-- base measure
[Total] = SUM ( T[Price] )
[Target Hit Date] = // This target value could be taken from a slicer // instead of hard-coding it to allow maximum
// flexibility. var __target = 25000 var __cummulativeTotals = ADDCOLUMNS ( VALUES ( T[Invoice Date] ), "CumulTotal", var __invDate = T[Invoice Date] var __cumulativeTotal = calculate ( [Total], T[Invoice Date] <= __invDate ) return __cummulativeTotal ) var __hitDate = minx ( filter( __cummulativeTotals, [CumulTotal] >= __target ), T[Invoice Date] ) return __hitDate

If your model has only this one table and does not have a proper Date table connected to it... then you should CHANGE THE MODEL and make it correct. If you don't want to suffer later on... but it's your call.

 

Of course, the above measure works for any set of customers, not only for one.

 

Best

Darek

View solution in original post

Anonymous
Not applicable

var __cummulativeTotals =  -- this one has an "s" on the end...
	ADDCOLUMNS (
		VALUES ( T[Invoice Date] ),
		"CumulTotal",
			var __invDate = T[Invoice Date]
			var __cummulativeTotal = -- this one does not... and it's had one "m" before
				calculate (
					[Total],
					T[Invoice Date] <= __invDate
				)
			return
				__cummulativeTotal -- and this one does not...
	)

Best

Darek

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

 

-- base measure
[Total] = SUM ( T[Price] )
[Target Hit Date] = // This target value could be taken from a slicer // instead of hard-coding it to allow maximum
// flexibility. var __target = 25000 var __cummulativeTotals = ADDCOLUMNS ( VALUES ( T[Invoice Date] ), "CumulTotal", var __invDate = T[Invoice Date] var __cumulativeTotal = calculate ( [Total], T[Invoice Date] <= __invDate ) return __cummulativeTotal ) var __hitDate = minx ( filter( __cummulativeTotals, [CumulTotal] >= __target ), T[Invoice Date] ) return __hitDate

If your model has only this one table and does not have a proper Date table connected to it... then you should CHANGE THE MODEL and make it correct. If you don't want to suffer later on... but it's your call.

 

Of course, the above measure works for any set of customers, not only for one.

 

Best

Darek

Hello Derek,

 

Thank you for your fast response.
I tried to run this but I am getting an error that __cummulativeTotals is not a valid table, variable or funtion name ( after the 'return' statement).

I do have a Date table in my model connected to this table.

 

Thanks,

Mansi

Anonymous
Not applicable

var __cummulativeTotals =  -- this one has an "s" on the end...
	ADDCOLUMNS (
		VALUES ( T[Invoice Date] ),
		"CumulTotal",
			var __invDate = T[Invoice Date]
			var __cummulativeTotal = -- this one does not... and it's had one "m" before
				calculate (
					[Total],
					T[Invoice Date] <= __invDate
				)
			return
				__cummulativeTotal -- and this one does not...
	)

Best

Darek

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.