Forum Discussion

bpopp's avatar
bpopp
Frequent Visitor
8 years ago
Solved

Using Calendar Table to Count Hourly Transactions (without missing hours)

I'm sure this is a common problem, but I've searched in vain for several hours. I have a calendar table and a transaction table. Each transaction has a calculated datetime for the start of the hour (ie. 3/4/2017 03:00:00) and this is related to a calendar table containing a datetime calculation for each of the 24hours in each day. I created an inactive relationship (Actual On Hour) tying the two tables together and used a measure to count the related records:

 

Actual Flights Per Hour = Calculate(COUNTROWS('Flights'),USERELATIONSHIP(Flights[Actual On Hour],'Calendar'[DateTime]))

 

This works fine:

 

 

but the problem is that I'm only getting records when there are matches. What I would like to see is every hour of every day, with zero's for the records where there are no relationships. Also, is there a way to do this without creating a relationship? I have four different dates and would prefer to not have to build inactive relationships for each.

 

Thanks so much,

 

bpopp

  • Hi bpopp,

     

    You can enable the option "Show items with no data" for the date column that is added to Matrix row.

     

    Also, make a little adjustment to your original formula:

    Actual Flights Per Hour =
    CALCULATE (
        COUNTROWS ( 'Flights' ),
        USERELATIONSHIP ( Flights[Actual On Hour], 'Calendar'[DateTime] )
    )
        + 0

     

    Best regards,

    Yuliana Gu

4 Replies

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi bpopp,

    What I would like to see is every hour of every day, with zero's for the records where there are no relationships. 

     

    What do you mean "with zero's for the records"? How are these records look like? Please provide sample data of 'Flights' table to better describe your scenario.

    How to Get Your Question Answered Quickly

     

    Regards,

    Yuliana Gu

    • bpopp's avatar
      bpopp
      Frequent Visitor

      In the example above, there were no matches for 8/13 2:00, so it just skipped it and went to 8/13 3:00. What I want is for it to include 8/13 2:00 with the count for that hour set to zero. 

      • v-yulgu-msft's avatar
        v-yulgu-msft
        Microsoft Employee

        Hi bpopp,

         

        You can enable the option "Show items with no data" for the date column that is added to Matrix row.

         

        Also, make a little adjustment to your original formula:

        Actual Flights Per Hour =
        CALCULATE (
            COUNTROWS ( 'Flights' ),
            USERELATIONSHIP ( Flights[Actual On Hour], 'Calendar'[DateTime] )
        )
            + 0

         

        Best regards,

        Yuliana Gu