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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

COUNTING AVERAGE OF THE ACTIVE PERIOD

Hi, 


Average Sessions =

AVERAGEX (

    VALUES ( 'Calendar'[Date] ),

       COALESCE ( [SDR ID average per CP ID], 0 )

)

 

This is the formula that returns the results correctly, averaging the usage data including the days when the unit wasn’t in use, but the issue is that My calendar starts in 2020 so the formula calculates the Averages including 0’s from 2020 not when my ‘Connector’ was first used, and runs to Q4 2022, as per my calendar.

With this function I am calculating the SDR ID(unique session number) Average per CP ID (unit number) Average, per day;
Some days the items are not in use, so that’s why the coalesce calculation is needed.


I am filtering the above function by the column (FACT TABLE[Connector]).

What can be done, to calculate the average usage, including 0’s within the days since the Connector has started working, not calculating any day before nor after that?

 

az.PNG

Example of my FACT TABLE Data:

AX.PNG

Thanks a lot,
J 

3 ACCEPTED SOLUTIONS

@Anonymous 
Thank you for your patience. Pleae try 

Average Sessions =
IF (
    NOT ISEMPTY ( 'FACT TABLE' ),
    AVERAGEX (
        VALUES ( 'Calendar'[Date] ),
        COALESCE ( [SDR ID average per CP ID], 0 )
    )
)

 

View solution in original post

@Anonymous 
Yes That is true. In fact I did not understand your logic or returning zero instead of blank. This how I would do it

Average Sessions =
AVERAGEX (
    SUMMARIZE (
        'Calendar',
        'Calendar'[Year],
        'Calendar'[Quarter],
        'Calendar'[Month],
        'Calendar'[Date]
    ),
    [SDR ID average per CP ID]
)

View solution in original post

Hi @Anonymous 
Would you like to connect perhaps with zoom or teams so we may look into it together? I have sometime now if you wish.

View solution in original post

21 REPLIES 21
tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to sample file with the solution https://www.dropbox.com/t/7MRcHUdlIDGXTHiL

1.png

Count Measur = 
VAR MinDate = CALCULATE ( MIN ( Sales2[Order Date] ), REMOVEFILTERS ( ) )
VAR MaxDate = CALCULATE ( MAX ( Sales2[Order Date] ), REMOVEFILTERS ( ) )
VAR FilteredDates = FILTER ( 'Date', 'Date'[Date] <= MaxDate && 'Date'[Date] >= MinDate )
VAR Result = 
    AVERAGEX (
        FilteredDates,
        COALESCE ( CALCULATE ( COUNT ( Sales2[CustomerKey] ) ), 0 )
    )
RETURN
    Result
tamerj1
Super User
Super User

@Anonymous 
Also Please try this version

Average Sessions =
AVERAGEX (
    SUMMARIZE (
        'Calendar',
        'Calendar'[Year],
        'Calendar'[Quarter],
        'Calendar'[Month],
        'Calendar'[Date]
    ),
    IF (
        NOT ISEMPTY ( CALCULATETABLE ( 'FACT TABLE' ) ),
        COALESCE ( [SDR ID average per CP ID], 0 )
    )
)
tamerj1
Super User
Super User

Hi @Anonymous 

please try

Average Sessions =
VAR FirstDateWithData =
    CALCULATE ( MIN ( TableName[Start Date] ), REMOVEFILTERS () )
VAR Dates =
    FILTER ( VALUES ( 'Calendar'[Date] ), 'Calendar'[Date] <= FirstDateWithData )
RETURN
    AVERAGEX ( Dates, COALESCE ( [SDR ID average per CP ID], 0 ) )
Anonymous
Not applicable

Hi tamerj1,
Thank you for that although it didn't work: I have changed the table name within the formula to match my table name: 

Average Sessions =
VAR FirstDateWithData =
    CALCULATE ( MIN ( 'FACT TABLE'[Start Date] ), REMOVEFILTERS () )
VAR Dates =
    FILTER ( VALUES ( 'Calendar'[Date] ), 'Calendar'[Date] <= FirstDateWithData )
RETURN
    AVERAGEX ( Dates, COALESCE ( [SDR ID average per CP ID], 0 ) )

When I include the formula to the visualisation - this is what I see. 
Capture.PNG

 

@Anonymous 

Sorry my mistake. It is the <= sign that should be >=

 

 

Average Sessions =
VAR FirstDateWithData =
    CALCULATE ( MIN ( TableName[Start Date] ), REMOVEFILTERS () )
VAR Dates =
    FILTER ( VALUES ( 'Calendar'[Date] ), 'Calendar'[Date] >= FirstDateWithData )
RETURN
    AVERAGEX ( Dates, COALESCE ( [SDR ID average per CP ID], 0 ) )

 

 
Anonymous
Not applicable

Hi tamerj1, 

 

Thank you very kindly for this, but it didn't change a thing. 
When I visualise this formula it still calculates everything, all the 0's from the beggining of my calendar 2020 including zeros in Q4 2022. 
Capture.PNG

 

@Anonymous 
Ok, Let's please try 

Average Sessions =
VAR FirstDateWithData =
    CALCULATE ( MIN ( 'FACT TABLE'[End Date] ), REMOVEFILTERS () )
VAR Dates =
    FILTER ( VALUES ( 'Calendar'[Date] ), 'Calendar'[Date] >= FirstDateWithData )
RETURN
    AVERAGEX (
        Dates,
        IF (
            NOT ISBLANK ( 'Calendar'[Date] ),
            COALESCE ( [SDR ID average per CP ID], 0 )
        )
    )
Anonymous
Not applicable

Hi tamerj1, 

The formula looks great but I get the exact same result.

Would anything got to to with the fact that we are calculating the average number of SDR ID  per average number of CP ID, by when the Connector is in use? See if this information changes anything. 
Ssample of my FACT TABLE:
Rapids example.PNG

 

 Thank you so much, 
J

@Anonymous 
What kind of relationship do you have between the two tables? Can you share a screenshot?

Anonymous
Not applicable

Thank you tamerj1,
See below. I also have the DIM table, but I am not sure if it's required for our measurement.  

12.PNG

 

 

@Anonymous 
Thank you for your patience. Pleae try 

Average Sessions =
IF (
    NOT ISEMPTY ( 'FACT TABLE' ),
    AVERAGEX (
        VALUES ( 'Calendar'[Date] ),
        COALESCE ( [SDR ID average per CP ID], 0 )
    )
)

 

Anonymous
Not applicable

Hi tamerj1, 

 

The formula definitely solved many issues, for example it solved the line chart, but sadly it doesn't calculates the averages correctly. The Q1 (The item started operating in March, so the function doesn't take the 1st 2 months into account), the same with Q3 - we only had July, but the function seems to be taking the average of all 3 months, whch skews the totals. 

I'm sorry to ask, but if you could take anoter look at this and see if you can figure this out. 
See an example.  

1.PNG

@Anonymous 
Yes That is true. In fact I did not understand your logic or returning zero instead of blank. This how I would do it

Average Sessions =
AVERAGEX (
    SUMMARIZE (
        'Calendar',
        'Calendar'[Year],
        'Calendar'[Quarter],
        'Calendar'[Month],
        'Calendar'[Date]
    ),
    [SDR ID average per CP ID]
)
Anonymous
Not applicable

Hi tamerj1, 

I thaught it worked but it didn't. 
It is now again not calculating the 0's when the items are not used between days. 
See the tables below. 
The one on the left representing the data with the help of that function, but what I need is t see the total as shown on the right. 
So the function should not calculate years, months days before it became operational, but it should count the 0's in between days. This is why I used the coalesce function earlier. 

12.PNG

 

 

@Anonymous 
Ok, let's try mix up both solutions

Average Sessions =
IF (
    NOT ISEMPTY ( 'FACT TABLE' ),
    AVERAGEX (
        SUMMARIZE (
            'Calendar',
            'Calendar'[Year],
            'Calendar'[Quarter],
            'Calendar'[Month],
            'Calendar'[Date]
        ),
        COALESCE ( [SDR ID average per CP ID], 0 )
    )
)

Also I noticed that your calendar table columns require proper sorting. You need to sort text columns using related numeric columns

Anonymous
Not applicable

Hi tamerj1, 
The formula again is not calculating the averages properly. 
Please let me know when you have enough of working on it. 
Capture.PNG

Thank you for your advise on the Cakendar Table. I will get that sorted. 
Best, 

J

Hi @Anonymous 
Would you like to connect perhaps with zoom or teams so we may look into it together? I have sometime now if you wish.

Anonymous
Not applicable

Yes, please, 
Thank you. Could you please send me your Teams invite? 
J

Anonymous
Not applicable

Hi tamerj1, 

 

Wow! Hats off to you Sir! Gosh, I've lots to learn. 
Huge thanks, with amazement! 
Thaaaanx! 😀

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.