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
PBI-Dash
Frequent Visitor

Calculating average between start and end dates

Hi,

I'm struggling with a DAX expression where I want to calculate the average volume between a start and end date and after that applying this measure to a visual where the numbers are shown correctly.

 

The dataset is very simple and looks like this:

Opportunity_IdEst VolumeOpportunity Date Contract StartOpportunity Date Contract End
123XXX1002021-08-122022-05-30
456XXX52021-09-012022-06-15
789XXX62022-01-172022-12-31
321XXX502022-06-20

2022-09-29


And I have a calendar table that has a relationship with this fact table through 'Calendar'[Date] 1:* 'fact_opportunites'[Opportunity_Date_Contract_Start].

 

Let's take an example:

We have an opportunity where the estimated volume is 100. The contract lenght is 5 months. In this case I want to take the sum of the volume (100) and divide it by the number of months (5). And then show this number (20) across those 5 months that this contract is valid. Is there any way to do this?

 

I've tried following this guide, but the result is that all the numbers are shown on either the month the contract starts or ends (depending on if the relationship is to 'fact_opportunites'[Opportunity_Date_Contract_Start] or 'fact_opportunites'[Opportunity_Date_Contract_End]). The measure looks like this:

 

Average estimated volume per Month = 
CALCULATE(
    SUMX(
        SUMMARIZE(
            filter(
                CROSSJOIN('fact_opportunities','Calendar')
                ,'Calendar'[Date] >= 'fact_opportunities'[Opportunity_Date_Contract_Start] && 'Calendar'[Date]<= 'fact_opportunities'[Opportunity_Date_Contract_End]
            )
                ,'fact_opportunities'[Opportunity_Id]
                ,'Calendar'[Date]
                ,fact_opportunities[Opportunity_Estimated_Volume]
                ,fact_opportunities[Opportunity_Date_Contract_Start]
                ,fact_opportunities[Opportunity_Date_Contract_End]
        )
        ,DIVIDE(
            [Volume]
            ,
            DATEDIFF(fact_opportunities[Opportunity_Date_Contract_Start],fact_opportunities[Opportunity_Date_Contract_End],MONTH)+1)
    )
)

 

So the average numbers are showing correctly, just that they are only showing on either the start or end month (depending on the relationship).

Or does somebody have a different approach on how to solve this?

 

Thank you in advance!

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your expected outcome of the visualization looks like, but please check the below picture and the attached pbix file.

I created no-relationship between the two tables in order to create a measure in a more easy way.

 

Untitled.png

 

Monthly expected volume measure: =
VAR _startingmonth =
    EOMONTH ( SELECTEDVALUE ( Data[Opportunity Date Contract Start] ), -1 ) + 1
VAR _endingmonth =
    EOMONTH ( SELECTEDVALUE ( Data[Opportunity Date Contract End] ), 0 )
VAR _monthcount =
    COUNTROWS (
        SUMMARIZE (
            FILTER (
                ALL ( 'Calendar' ),
                'Calendar'[Date] >= _startingmonth
                    && 'Calendar'[Date] <= _endingmonth
            ),
            'Calendar'[Month & Year CC]
        )
    )
VAR _EstVolumeAVG =
    DIVIDE ( SUM ( Data[Est Volume] ), _monthcount )
RETURN
    IF (
        MIN ( 'Calendar'[Date] ) >= _startingmonth
            && MAX ( 'Calendar'[Date] ) <= _endingmonth,
        _EstVolumeAVG,
        0
    )

 


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.

Hi,

Thanks for the reply!

 

Sorry, I forgot to mention how I'd like to visualize it.

In this case I'd like to visualize the numbers in a line chart where I also show the orders current year as well as orders last year. So this measure would somehow need to be connected to the calendar table that I'm using as an axis.

 

Sincerely

Dash

Hi,

Thank you for your feedback.

I am not sure if I understood your inquiry correctly, but please check the below picture and the attached pbix file.

 

Untitled.png


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.

Hi,

Sorry, I was a bit unclear.

 

I need the measure in the same visual as my other measures that are depandant on the calendar table. So I have two different fact-tables, one with orders and one with estimated volume. Both are connected to the calendar table at the moment. And I would be very happy if it was possible to have all measures in the same line graph.

 

 

Sincerely

Dash

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.