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 August 31st. Request your voucher.

Reply
neiluj
New Member

How to calculate the average of a count by category

Hi,

 

I have a dataset in which one record represents one sale. I have a datetime column and a calculated column 'hour' based on the datetime column. Let's say:

 

IDDate HourQuantity

1

2022-08-20 09:00:00

 

9

2
22022-08-20 09:30:00 93
32022-08-20 09:40:00 94
42022-08-23 09:00:00 92
52022-08-24 09:00:00 94
62022-08-24 9:20:00 96
72022-08-24 12:10:00 123

 

I also have a measure 'Number of sales' (calculated by taking the count of ID).

 

I would like to create 2 additional measures: 

  • The average of sales (number of records) we get per hour each day (in this example (3+1+2)/3 = 2 between 9 and 10, and 1 bewteen 12 and 13).
  • The average of items sold per hour each day (in this example ((2+3+4) +(2) +(4+6))/3 = 7 between 9 and 10).

So that I could get a graph with on the x-axis the hours (from 0 to 24) and as values the above mentioned averages.

 

Hoping somebody could help

 

Best regards

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pibx file.

I suggest having a time table like the below.

 

Picture1.png

 

Avg number of records: = 
AVERAGEX (
    ALL ( 'Calendar'[Date] ),
    CALCULATE ( COUNTROWS ( VALUES ( Data[ID] ) ) )
)

 

Avg number of Qty: = 
AVERAGEX (
    ALL ( 'Calendar'[Date] ),
    CALCULATE ( SUM(Data[Quantity] ) )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pibx file.

I suggest having a time table like the below.

 

Picture1.png

 

Avg number of records: = 
AVERAGEX (
    ALL ( 'Calendar'[Date] ),
    CALCULATE ( COUNTROWS ( VALUES ( Data[ID] ) ) )
)

 

Avg number of Qty: = 
AVERAGEX (
    ALL ( 'Calendar'[Date] ),
    CALCULATE ( SUM(Data[Quantity] ) )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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