Forum Discussion

PC2022's avatar
PC2022
Helper III
2 years ago
Solved

Weighted average within a certain date range

I calculated weighted average of the cost using "Quick measure" in Power BI:

 

I need to calculate weighted average within a six month date range (for example, if the bid dates of the project are between 5/1/2023 and 10/1/2023). How would i modify the weighted avg formula or should i create new column? If so, please help with DAX. Thank you.

 

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi PC2022 ,

    You can create a measure as below to get it:

    Weighted Average 6 Months =
    CALCULATE (
        SUMX (
            FILTER (
                'Test Full Pay Items',
                'Test Full Pay Items'[Bid Date] >= DATE ( 2023, 5, 1 )
                    && 'Test Full Pay Items'[Bid Date] <= DATE ( 2023, 10, 1 )
            ),
            'Test Full Pay Items'[Highest Bid] * 'Test Full Pay Items'[Qty]
        )
            / SUMX (
                FILTER (
                    'Test Full Pay Items',
                    'Test Full Pay Items'[Bid Date] >= DATE ( 2023, 5, 1 )
                        && 'Test Full Pay Items'[Bid Date] <= DATE ( 2023, 10, 1 )
                ),
                'Test Full Pay Items'[Qty]
            )
    )

    If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your visual settings. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards

2 Replies

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

    Do not include sensitive information or anything not related to the issue or question.

    If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216

    Please show the expected outcome based on the sample data you provided.

    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PC2022 ,

    You can create a measure as below to get it:

    Weighted Average 6 Months =
    CALCULATE (
        SUMX (
            FILTER (
                'Test Full Pay Items',
                'Test Full Pay Items'[Bid Date] >= DATE ( 2023, 5, 1 )
                    && 'Test Full Pay Items'[Bid Date] <= DATE ( 2023, 10, 1 )
            ),
            'Test Full Pay Items'[Highest Bid] * 'Test Full Pay Items'[Qty]
        )
            / SUMX (
                FILTER (
                    'Test Full Pay Items',
                    'Test Full Pay Items'[Bid Date] >= DATE ( 2023, 5, 1 )
                        && 'Test Full Pay Items'[Bid Date] <= DATE ( 2023, 10, 1 )
                ),
                'Test Full Pay Items'[Qty]
            )
    )

    If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your visual settings. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards