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
mccollough
Helper I
Helper I

Average Frequency by Hour Calculation

Hello Everyone!

 

Penny for your thoughts

 

Fact Table

Exam Id                Report Date           Report Hour            Employee                 Location                   Task Type                     
1A6/1/202010:00 AMJohn DoeOfficeAB
1B6/1/20205:00 AMJane DoeHomeAB
1C6/1/202010:00 AMBatmanBat CaveCD
1D6/1/20203:00 PMJohn DoeOfficeCD
2A6/1/20205:00 PMJane DoeHomeAB
2B6/1/20207:00 AMBatmanBat CaveEF
2C6/2/20208:00 AMJohn DoeHomeAB
2D6/2/20201:00 AMJane DoeBat CaveAB
3A6/2/20203:00 PMBatmanOfficeCD
3B6/2/20204:00 PMJohn DoeHomeEF
3C6/2/20206:00 PMJane DoeBat CaveAB
3D6/2/20209:00 AMBatmanOfficeCD
5A6/3/20203:00 AMJohn DoeBat CaveCD
4B6/3/20205:00 AMJane DoeOfficeEF
5C6/3/20207:00 AMBatmanHomeAB
4C6/3/202010:00 AMBatmanHomeAB
4A6/3/202011:00 AMJohn DoeBat CaveAB
5B6/3/20205:00 PMJane DoeOfficeEF
6A6/4/20208:00 PMJohn DoeOfficeCD
6B6/4/20201:00 AMJane DoeHomeEF
6C6/4/20202:00 AMBatmanBat CaveAB
7A6/4/20204:00 AMJohn DoeOfficeCD
7B6/4/20207:00 PMJane DoeHomeCD
7C6/4/20209:00 AMBatmanBat CaveUS
8A6/5/202010:00 AMNed FlandersHomeUS
8B6/5/20203:00 PMBart SimpsonOfficeAB
9A6/6/202011:00 AMJohn DoeHomeEF
9B6/6/20205:00 AMJane DoeBat CaveCD
9C6/6/202010:00 AMBatmanOfficeCD
10A6/7/20203:00 PMJohn DoeHomeAB
11A6/8/202012:00 PMJane DoeBat CaveEF
11B6/8/20201:00 PMBatmanOfficeAB
11C6/8/20208:00 AMJohn DoeBat CaveCD
11D6/8/20201:00 AMJane DoeOfficeAB
11E6/8/20203:00 PMBatmanHomeEF
11F6/8/20204:00 PMJohn DoeBat CaveCD
12A6/9/20206:00 PMJane DoeOfficeUS
12B6/9/20202:00 PMBatmanHomeCD
12C6/9/202011:00 AMJohn DoeOfficeAB



Goal: 
Visualize the average number of exams and task types by hour

Current Approach:

Calculate the number the of 'Task Types' filtered  by 'Report Hour' and visualize that on a stacked column chart as follows
Axis: Report Hour
Legend: Report Type
Values: Average TaskType by Report Hour

DAX for Average TaskType by Report Hour

Average TaskType by ReportHour =
 
AVERAGEX
(
   'Fact Table',
    CALCULATE
    (
         COUNT('Fact Table'[Task Type]),
         FILTER('Fact Table', 'Fact Table'[Report Hour])
    )
)


Result:

mccollough_4-1627064903365.png

 

 

I still get a result that shows me the number of Exam Types by Hour.

 

Where did I go wrong? How Can I do this correctly?

Data Validation Value:

These are the exam frequencies by hour and Task Type over the 9 days covered in the data set
I want to know what the average number of exam types by hour.
 

mccollough_5-1627064960384.png

So over 9 days there were 9 different 10:00 AM time windows
5 exams occured in that time window that time period

mccollough_3-1627064791600.png


That means on average there were 0.55 exams in the 10:00 AM time window (5 exams/ 9 days)
    - 0.22 of them were of type AB (2 exams/9 days)

    - 0.22 of them were of type CD (2 exams/9 days)
    - 0.11 of them were of type US (1 exam/9 days)

0.22 (AB) + 0.22 (CD) + 0.11 (US) = 0.55 (Total)


I would like to visualize there number for each time slot!
(EX. What does this look like for 11:00 AM, 12:00 PM, 1:00 PM, etc.)


Thank you so much for all your help!!!!

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@mccollough here are 3 measures to get this going. these are self-explanatory but if you need further details, let me know.

 

Count Exams = COUNTROWS ( Exam1 )  //exam1 is a name of the table in my model

Number of Days = CALCULATE ( DISTINCTCOUNT ( Exam1[Report Date] ), ALLSELECTED () )

Avg per Hour = 
VAR __examDays = Exam1[Number of Days]
RETURN
SUMX (  
    SUMMARIZE ( 
        Exam1, 
        Exam1[Report Hour], 
        Exam1[Task Type], 
        "@AVG",  DIVIDE ( [Count Exams], __examDays ) 
    ), 
    [@AVG] 
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

@mccollough here are 3 measures to get this going. these are self-explanatory but if you need further details, let me know.

 

Count Exams = COUNTROWS ( Exam1 )  //exam1 is a name of the table in my model

Number of Days = CALCULATE ( DISTINCTCOUNT ( Exam1[Report Date] ), ALLSELECTED () )

Avg per Hour = 
VAR __examDays = Exam1[Number of Days]
RETURN
SUMX (  
    SUMMARIZE ( 
        Exam1, 
        Exam1[Report Hour], 
        Exam1[Task Type], 
        "@AVG",  DIVIDE ( [Count Exams], __examDays ) 
    ), 
    [@AVG] 
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Worked like a charm!

Thank you for your help!!!

parry2k
Super User
Super User

@mccollough is this the output you are expecting:

 

parry2k_0-1627072288859.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k That's exactly what I was looking for! Would you mind breaking down how you accomplished that?

parry2k
Super User
Super User

@mccollough not sure what you want the expected result to be? Can you explain?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k 

Aha! There's part of the problem! 
I was thinking about it the wrong way.
I updated the Data validation segment of my post to better reflect what I'm looking for.

Unfortunately I still don't know how to go about making DAX perform that calculation.

 

PS 
I also modified the fact table slightly to reflect how the data actually appears in my real dataset

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.