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
aarhus_economic
Regular Visitor

Grouping and intermediate calculations

I have a data frame/Table as this: 

 

 

DateStart; DateEnd; Group_Var; Price; Amount
2017-01-01; 2017-12-31; A; 9; 5
2017-06-01; 2017-12-31; A; 4; 10
2017-01-01; 2017-12-31; B; 5; 5
2017-06-01; 2017-12-31; B; 9; 1

I want a new table where I want to do the calculation: 

 

 

DateEnd - DateStart (in hours) * Price * Amount or : 
Group_var A; 9 * 5 * 8760 + 4 * 10 * 5137 = 599680
Group_var B; 5 * 5 * 8760 + 9 * 1 * 5137 = 265233

So, end result is: 

 

 

Group_var; Sum_Price_Over_Time
A; 599680
B; 265233

 

I've figured out the 

 

SUMMARIZE('Table' ;'Table' [Group_Var];"Value"; SUM('Table'[Price]))

 

But I am not sure how I can do the time diff and I get and error if I try to:

SUM(Price * Value) 

 

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

basically a measure like this, should work

Measure = 
CALCULATE(
SUMX(
	'Table1'
	,DATEDIFF('Table1'[DateStart],'Table1'[DateEnd],HOUR)*'Table1'[Price]*'Table1'[Amount]
)
)

But maybe you have to trick the DATEDIFF() a little by adding some extra hours. Depending on what the start and end date represents. Meaning: are 2017-01-01 to 2017-01-02 24hours or 48

 

Hope this is what you are looking for

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

1 REPLY 1
TomMartens
Super User
Super User

Hey,

 

basically a measure like this, should work

Measure = 
CALCULATE(
SUMX(
	'Table1'
	,DATEDIFF('Table1'[DateStart],'Table1'[DateEnd],HOUR)*'Table1'[Price]*'Table1'[Amount]
)
)

But maybe you have to trick the DATEDIFF() a little by adding some extra hours. Depending on what the start and end date represents. Meaning: are 2017-01-01 to 2017-01-02 24hours or 48

 

Hope this is what you are looking for

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.