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
Roberto456
Resolver I
Resolver I

how to SUMX for datediff totals

Hello All.

 

I'm trying to add up the days between orders for all customers.  Below is my formula.

 

Days Between Orders 1:2 =

VAR DATEDIFFVAR = DATEDIFF([Invoice Date (Min)],[Invoice Date (Min) R2],DAY)
VAR TOTALTABLE = SUMMARIZE('(SQL) Cart','(SQL) Cart'[Customer_ID],"DAYS BETWEEN",DATEDIFFVAR)

RETURN
IF(HASONEVALUE('(SQL) Cart'[Customer_ID]),DATEDIFFVAR,SUMX(TOTALTABLE,DATEDIFFVAR))Capture.JPG
As you can see its not adding up the days properly.
 
Does anyone know why?
1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi  @Roberto456 

Just adjust the formula as below:

New Days Between Orders 1:2 =
VAR DATEDIFFVAR = DATEDIFF([Invoice Date (Min)],[Invoice Date (Min) R2],DAY)
VAR TOTALTABLE = SUMMARIZE('(SQL) Cart','(SQL) Cart'[Customer_ID],"DAYS BETWEEN",DATEDIFF([Invoice Date (Min)],[Invoice Date (Min) R2],DAY))

RETURN
IF(HASONEVALUE('(SQL) Cart'[Customer_ID]),DATEDIFFVAR,SUMX(TOTALTABLE,[DAYS BETWEEN]))
 

Result:

9.JPG

Regards,

Lin

Community Support Team _ Lin
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
v-lili6-msft
Community Support
Community Support

hi  @Roberto456 

Just adjust the formula as below:

New Days Between Orders 1:2 =
VAR DATEDIFFVAR = DATEDIFF([Invoice Date (Min)],[Invoice Date (Min) R2],DAY)
VAR TOTALTABLE = SUMMARIZE('(SQL) Cart','(SQL) Cart'[Customer_ID],"DAYS BETWEEN",DATEDIFF([Invoice Date (Min)],[Invoice Date (Min) R2],DAY))

RETURN
IF(HASONEVALUE('(SQL) Cart'[Customer_ID]),DATEDIFFVAR,SUMX(TOTALTABLE,[DAYS BETWEEN]))
 

Result:

9.JPG

Regards,

Lin

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

Thank you 🙂

amitchandak
Super User
Super User

I did not get the problem completely.

 

Refer to this file for Way 3 and Way 4. You just have to use same table :https://www.dropbox.com/s/y47ah38sr157l7t/Order_delivery_date_diff.pbix?dl=0

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.