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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Calculate Average over the selected date period from Slicer

Hi Experts

 

Need a measure to calculate the Average between the dates as shown the the slicer selection, has to be dynamic based on the slicer slection and not fixed min and max dates.

 

Checkers111_0-1658675208632.png

 

2 ACCEPTED SOLUTIONS
jennratten
Super User
Super User

Hello - 

Here is an example.  You will need to modify the table and column names to match your scenario.  If you need more assistance, please post examples of your scripts and data.

 

 

AvgSalesAmount:= 
VAR MinDate = CALCULATE ( MIN('Dates'[Date]),ALLSELECTED('Dates'[Date]) )
VAR MaxDate = CALCULATE ( MAX('Dates'[Date]),ALLSELECTED('Dates'[Date]) )
VAR Period =
    DATESBETWEEN ( 'Dates'[Date], MinDate, MaxDate )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Dates'[Date] ), -- average by __ (date, month, etc)
            [Sales Amount]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Dates'[Date] )
VAR LastDateWithSales = MAX ( Sales[Order Date] )
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

 

View solution in original post

Anonymous
Not applicable

This was enough to make it work:

 

MEASURE Avg_Selected_Period = CALCULATE(AVERAGEX('GasBBActualFlowStorageLast31',[Flow]),ALLSELECTED('GasBBActualFlowStorageLast31'[GasDate]))

View solution in original post

3 REPLIES 3
jennratten
Super User
Super User

Hello - 

Here is an example.  You will need to modify the table and column names to match your scenario.  If you need more assistance, please post examples of your scripts and data.

 

 

AvgSalesAmount:= 
VAR MinDate = CALCULATE ( MIN('Dates'[Date]),ALLSELECTED('Dates'[Date]) )
VAR MaxDate = CALCULATE ( MAX('Dates'[Date]),ALLSELECTED('Dates'[Date]) )
VAR Period =
    DATESBETWEEN ( 'Dates'[Date], MinDate, MaxDate )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Dates'[Date] ), -- average by __ (date, month, etc)
            [Sales Amount]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Dates'[Date] )
VAR LastDateWithSales = MAX ( Sales[Order Date] )
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

 

Anonymous
Not applicable

The following code generates the following error:

 

MEASURE Average_Period = 
VAR MinDate = MIN(('Date'[Date]), ALLSELECTED('Date'[Date]))
VAR MaxDate = MAX(('Date'[Date]), ALLSELECTED('Date'[Date]))
VAR Period = DATESBETWEEN ( 'Date'[Date], MinDate, MaxDate )
VAR Result = 
    CALCULATE ( 
        AVERAGEX ( 
            'GasBBActualFlowStorageLast31',
            [Flow]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Date'[Date] )
VAR LastDateInPeriod = MAX ( 'GasBBActualFlowStorageLast31'[GasDate] )
RETURN
    IF ( FirstDateInPeriod <= LastDateInPeriod, Result )

 

Error: A single value for column `Date`  in table `Date` cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Anonymous
Not applicable

This was enough to make it work:

 

MEASURE Avg_Selected_Period = CALCULATE(AVERAGEX('GasBBActualFlowStorageLast31',[Flow]),ALLSELECTED('GasBBActualFlowStorageLast31'[GasDate]))

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.