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
tcboutte
Regular Visitor

Calculating Price Indices over a Date Range

I am struggling to figure out the best combination of measures to help a Power Bi visual match a source Excel file. The source file contains a price for each month of the year which are represented below and the Total column is what I am struggling with. "DaysSelected" is a measure that is there for my reference and reacts to my date slicer.

 

The correct value for the Total column is 94.38 and is to be calculated as the sum of: Price per month *(days in that month/DaysSelected). For this example that would be 82.98*(31/90) + 91.63*(28/90) + 108.26*(31/90) = 94.38. 

 

tcboutte_1-1659369950764.png

The measure in the matrix above is NYMEX-CL = CALCULATE(AVERAGE('Price Indices'[Amount]),'Price Indices'[Category] = "NYMEX-CL") and below is the input data and DaysInMonth is a calculated column that I added. Any suggestions?

 

tcboutte_0-1659369913792.png

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @tcboutte ,

According to your description, Here's my solution. Create a measure.

NYMEX-CL =
VAR _Av =
    CALCULATE (
        AVERAGE ( 'Price Indices'[Amount] ),
        'Price Indices'[Category] = "NYMEX-CL"
    )
RETURN
    IF (
        ISINSCOPE ( 'Price Indices'[Date] ),
        _Av,
        SUMX (
            FILTER ( 'Price Indices', 'Price Indices'[Category] = "NYMEX-CL" ),
            'Price Indices'[Amount]
                * DIVIDE ( 'Price Indices'[DaysInMonth], [DaysSelected] )
        )
    )

Get the correct result.

vkalyjmsft_0-1659597228953.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-yanjiang-msft
Community Support
Community Support

Hi @tcboutte ,

According to your description, Here's my solution. Create a measure.

NYMEX-CL =
VAR _Av =
    CALCULATE (
        AVERAGE ( 'Price Indices'[Amount] ),
        'Price Indices'[Category] = "NYMEX-CL"
    )
RETURN
    IF (
        ISINSCOPE ( 'Price Indices'[Date] ),
        _Av,
        SUMX (
            FILTER ( 'Price Indices', 'Price Indices'[Category] = "NYMEX-CL" ),
            'Price Indices'[Amount]
                * DIVIDE ( 'Price Indices'[DaysInMonth], [DaysSelected] )
        )
    )

Get the correct result.

vkalyjmsft_0-1659597228953.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Much appreciated! I just need to make one small change to how I was calculating my DaysSelected, but your measure did the trick after that. Thanks!

Hi @tcboutte ,

You're welcome! I thought DaysSelected was a column you've built, I see it in your screenshot。

vkalyjmsft_0-1659677296814.png

If not, just create a new table use GENERATESERIES function like this:

vkalyjmsft_1-1659677722314.png

Best Regards,
Community Support Team _ kalyj

 

All good! DaysSelected was actually a measure that calculated how many were currently selected on that page's slicer since we have about 2 years of data to work from.

Hi @tcboutte ,

If I understand correctly, you want to count the numbers be selected in the slicer, simply try:

DaysSelected = COUNTROWS(ALLSELECTED('Table'[Column]))

Get the correct value.

vkalyjmsft_0-1659922794377.png

Best Regards,
Community Support Team _ kalyj

amitchandak
Super User
Super User

@tcboutte , Try a measure like

 

Rolling 3 = calculate(AverageX(Values('Date'[MONTH Year]),calculate([Measurement]* day(eomonth(max('Date'[date]),0))/90)),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH))
)

Thanks. I am working with this now, but it looks like it be built to only handle the total days being 90. I'll need it to work with any number of months selected from my date slicer so that the denominator is dynamic. Do you think that is possible?

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.