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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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))
)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.