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
Anonymous
Not applicable

DAX - Calculating Averages per hour

Hi,

 

I am trying to calculate the average number of active documents at any given hour in a specific date range. (In the date range, 01/01/18 - 11/02/18, how many active documents have there been, on average, at 11:00?). I can get this to work for 1 day at a time, but cannot get it to do it over the date range.

 

On my report it is the graph I am trying to get to work, the 2 tables are essentially just my workings out/tests. I know the documents created/completed measures (counts and averages) are correct, but not the active documents measures.

 

My pbix file is https://drive.google.com/file/d/13PouI5wPiBIbaUD2CdLwUO2fgzeXZvZ-/view?usp=sharing

 

The trend should look like the Active Docs per day column in the image below.

DT active trend.PNG

Thanks for your help!

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous 

 

You may try using AVERAGEX.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-chuncz-msft 

 

Thanks for replying. Unfortunately averagex doesn't quite work in this situation since the table I would be using is one full of measures. I essentially need to find the sum of the number of active documents at each hour and then divide that by the number of days in the date range.

I can do the second bit and divide by the number of days, but I cannot seem to find the sum per hour.

The red in the picture shows the measures. The count T1 is the measure I am interested in and it works when I have both dates and times on the table, but when I take the date column out, the measure sets the values to 0.

DT active trend1.PNGDT active trend.PNG

The DAX I am using is as follows

ActivePerHourCountTest1 = 
CALCULATE(
    CALCULATE(
        COUNTA(IMSDocuments[Unique Document Id]) + 0,
        FILTER(
            IMSDocuments, 
            IMSDocuments[Creation Date] + IMSDocuments[Creation Hour] <= SELECTEDVALUE(Dates[Date]) + SELECTEDVALUE(Times[Time])
        ), 
        FILTER(
            IMSDocuments, 
            OR(
                ISBLANK(IMSDocuments[Completion Date]),
                IMSDocuments[Completion Date] + IMSDocuments[Completion Hour] > SELECTEDVALUE(Dates[Date]) + SELECTEDVALUE(Times[Time])
            )
        )
    ),
    CROSSFILTER(Dates[Date], IMSDocuments[Creation Date], NONE)
)  

 For this date range, the table/count should sum up the values for both days. The second image should look like this

DT active trend3.PNG

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.