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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jmp
Frequent Visitor

Normalize aggregate using datetime hierarchy

Say I have two columns, Timestamp (datetime type) and TimeSpent (duration type represented in hours or whatever).

Now i want to calculate the total TimeSpent (Sum) in % using the Timestamp field as axis, creating a hierarchy over year, quarter, month, day. It is quite easy to calculate just the sum of the duration, but then i want to divide that number with the relevant level in the hierarchy, i.e. if the navigation point in the hierarchy is "day", i want to divide the duration with 24 hours and so forth.

 

The closest i can get is dividing with MAX(Timestamp)-MIN(Timestamp) within the "group", however this is not optimal since i have voids in the timeline in the original table.

 

Any idea how to solve this?

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

basically i would consider to create an additional calendar table that just contains dates.

 

Add an addtional column that inside your "fact" table that also just contains a date, without the time part.

Relate the tables with Calendar on the one-side and the fact table on the many-side.

 

Create a Measure that counts the timestamps, this measure than can be used as divisor for the sum of the durations.

 

This will work for a hierarchy like Day -> Month -> Quarter -> Year

 

If you need a more fine grained axis, than you have to build a more calendar/time table. Please be aware that you need a matching column in both of your tables, if the grain has to be an hour the values for the columns should look like this:

2018-08-14 00:00:00

2018-08-14 01:00:00

...

2018-08-14 23:00:00

2018-08-15 00:00:00

...

 

Hopefully this gives you an idea.

 

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

2 REPLIES 2
TomMartens
Super User
Super User

Hey,

 

basically i would consider to create an additional calendar table that just contains dates.

 

Add an addtional column that inside your "fact" table that also just contains a date, without the time part.

Relate the tables with Calendar on the one-side and the fact table on the many-side.

 

Create a Measure that counts the timestamps, this measure than can be used as divisor for the sum of the durations.

 

This will work for a hierarchy like Day -> Month -> Quarter -> Year

 

If you need a more fine grained axis, than you have to build a more calendar/time table. Please be aware that you need a matching column in both of your tables, if the grain has to be an hour the values for the columns should look like this:

2018-08-14 00:00:00

2018-08-14 01:00:00

...

2018-08-14 23:00:00

2018-08-15 00:00:00

...

 

Hopefully this gives you an idea.

 

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

Thank you very much for this tip.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.