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
Anonymous
Not applicable

datediff calculation

I want to create a calculation a gap between two date columns and sums up as numerator to be divided by another column, it seems datediff not work in calculation, so how can I calculation days of gap between twe date column in calculation?

1 ACCEPTED SOLUTION

@Anonymous you haven't showed enough about what you want to get. Anyway I wrote some options, let me know if one of them worked:

 

V1A = 

SUMX(
	'adshrs_demand_detail_d',
	('adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]) / COUNT('adshrs_demand_detail_d'[request_headcount])
	)


V1' = 

SUMX(
	'adshrs_demand_detail_d',
	('adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]) / COUNTROWS('adshrs_demand_detail_d')
	)

V2 =
DIVIDE(
	SUMX(
		'adshrs_demand_detail_d',
		'adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]
	),
	COUNT('adshrs_demand_detail_d'[request_headcount])
)


V2' =
DIVIDE(
	SUMX(
		'adshrs_demand_detail_d',
		'adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]
	),
	COUNTROWS('adshrs_demand_detail_d')
)

 

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

4 REPLIES 4
SpartaBI
Community Champion
Community Champion

@Anonymous you can just do date2 - date1 for these use cases in general.

You probably need to wrap it with more logic, but can't say nothing with the info you gave 🙂 If you don't succeed please share a sample data (copt paste a table here) and the result you want to get

Anonymous
Not applicable

this is the data and I want the sum(date1-date2) as numerator

 

@Anonymous you haven't showed enough about what you want to get. Anyway I wrote some options, let me know if one of them worked:

 

V1A = 

SUMX(
	'adshrs_demand_detail_d',
	('adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]) / COUNT('adshrs_demand_detail_d'[request_headcount])
	)


V1' = 

SUMX(
	'adshrs_demand_detail_d',
	('adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]) / COUNTROWS('adshrs_demand_detail_d')
	)

V2 =
DIVIDE(
	SUMX(
		'adshrs_demand_detail_d',
		'adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]
	),
	COUNT('adshrs_demand_detail_d'[request_headcount])
)


V2' =
DIVIDE(
	SUMX(
		'adshrs_demand_detail_d',
		'adshrs_demand_detail_d'[date2] - 'adshrs_demand_detail_d'[date1]
	),
	COUNTROWS('adshrs_demand_detail_d')
)

 

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Tahreem24
Super User
Super User

@Anonymous , I wonder how DateDiff is not working. Can you share the sample data and required output in order to better understand your scenario.

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

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.