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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
sam0007
Frequent Visitor

Count of instances by day and hour

Spoiler
 

Hello PBI community,

I'm looking to count number of loads by hour. The dataset spans over two days and the table visual is calculating the measure incorrectly. What am I doing wrong here? How can I show the visual over two days?

I have some loads that are loaded on 22/06/2021 to be delivered on 23/06/2021. The matrix visual only displays 23/06/2021 data.

When DAX is calculating the measure it is counting by hour only and not on the date. Example:
for 18:00 hours, on 22/06/2021 @ 18:00 hours I have 6 loads and on 23/06/2021 @ 18:00 hours I have 1. However in the visual it is showing as 23/6/2021 @ 18:00 hours as 7 (which is 6 from 22/06 + 1 from 23/06)

I have selected cross filter direction as 'Both' for creating relationship between date and hour table with data table. 

Below is the link for power bi file and excel file which shows the difference.

 

Appreciate your help!

 

https://www.dropbox.com/sh/l94j7rb9iavm783/AADqJs6dOZU06anbmdfftyiUa?dl=0 

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @sam0007 ,

First, bi-directional relations are to be used in very rare cases. You don't need them here.

Second, here is the refernce to the correct usage of USERELATIONSHIP function: https://dax.guide/userelationship/ 

I don't know the final result you want to achieve, but from what you've mentioned, you can try to change your measure in the next way:

Count of loads by hour =
CALCULATE (
    COUNT ( f_DataTable[Route ID] ),
    USERELATIONSHIP ( f_DataTable[Load Date], d_DateTable[Date] ),
    USERELATIONSHIP ( f_DataTable[Load Time], d_HourTable[Time] )
)

ERD_0-1626161572884.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
sam0007
Frequent Visitor

@ERD That's amazing! Thanks for your help 🙂

ERD
Community Champion
Community Champion

Hi @sam0007 ,

First, bi-directional relations are to be used in very rare cases. You don't need them here.

Second, here is the refernce to the correct usage of USERELATIONSHIP function: https://dax.guide/userelationship/ 

I don't know the final result you want to achieve, but from what you've mentioned, you can try to change your measure in the next way:

Count of loads by hour =
CALCULATE (
    COUNT ( f_DataTable[Route ID] ),
    USERELATIONSHIP ( f_DataTable[Load Date], d_DateTable[Date] ),
    USERELATIONSHIP ( f_DataTable[Load Time], d_HourTable[Time] )
)

ERD_0-1626161572884.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.