<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic REALLY hoping for some help on Dynamic Weighted Averages please in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/REALLY-hoping-for-some-help-on-Dynamic-Weighted-Averages-please/m-p/3483780#M133255</link>
    <description>&lt;P&gt;Hi there!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to Power BI and am really hoping for some help. I'm attaching two versions of the PBIX and an Excel showing the general workings that I'm aiming for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.google.com/spreadsheets/d/1daxyqJRyU8AEPl3StNATq-rduCnzzmyT/edit?usp=share_link&amp;amp;ouid=108415431817116777667&amp;amp;rtpof=true&amp;amp;sd=true" target="_self" rel="nofollow noopener noreferrer"&gt;Excel workings&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1nVubiCYy6O5k-oY17jraFmMsboTn54Fr/view?usp=share_link" target="_self" rel="nofollow noopener noreferrer"&gt;PBIX where overall weighted average is correct but it can't rebalance where user applies filters&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1XslppNIOjm4aUkiiyTqkyDHkaiGODu3P/view?usp=share_link" target="_self" rel="nofollow noopener noreferrer"&gt;PBIX where the weight column correctly rebalances when user applies filters, but then weighted avera...&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE: only difference between these two files is the FlexibleGroupWeight measure&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially I have a portfolio with a list of stock weights. There are multiple rows per stock, duplicating the stock weight data. Each unique row is for various metrics on the stocks (ROE, beta etc). For each stock, I need to calculate a weighted average for a metric. When the metric isn't available for a stock, it should automatically rebalance (to 100% in total) the weights for the stocks where the data is available.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Crucially, I'm hoping the weighted average can be dynamic. i.e. when users filter clicking within the dashboard, the weighted average recalculates. So if we filtered to four 5% stocks that total 20% of portfolio, because it's filtered this would all rebalance to 100% and the 5% stocks all become 25% for example.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully you can see what I'm getting at - I've included an Excel workbook to show how I would use SUMIFs to achieve the first of these effects (filtering out and rebalancing stocks based on data availablility).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the Excel shows arrives at the correct aggregate weighted averages for each metric based on the sum of [RebalancedWeight]*[Value] rows for a metric. You can see these correct weighted averages in Column I.&lt;/P&gt;&lt;P&gt;In the Power BI reports, it hinges on the "FlexibleGroupWeight" measure.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In the first file, everything calculates correctly at the aggregate level, and therefore produces correct weighted average metrics ("WA-Metric" column). HOWEVER - &lt;STRONG&gt;it cannot handle user-applied filters (the measure is only using ALLEXCEPT)&lt;/STRONG&gt;.&lt;/LI&gt;&lt;LI&gt;In the second PBIX, the &lt;STRONG&gt;"FlexibleGroupWeight" measure can handle the user-filtering process&lt;/STRONG&gt;.. You click the pie chart to filter on a particular sector, and the number in the first column correctly drops to just the % of the portfolio we are filtered to. The rebalancing &lt;STRONG&gt;&lt;EM&gt;should&lt;/EM&gt; &lt;/STRONG&gt;then work off this smaller total to do a weighted average in that sector only. However - suddenly the actual weighted average metrics are WAY out and it looks as though they become the sum of all the individual stock metric values..&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In latter case my measure uses ALLSELECTED whereas first case uses ALLEXCEPT... Is there some way of combining these two formulas please to get the desired effect? I think that it what would finally get me there!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANK YOU SO SO MUCH IN ADVANCE FOR ANY HELP!!&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2023 15:56:22 GMT</pubDate>
    <dc:creator>jmillsjmills</dc:creator>
    <dc:date>2023-10-18T15:56:22Z</dc:date>
    <item>
      <title>REALLY hoping for some help on Dynamic Weighted Averages please</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/REALLY-hoping-for-some-help-on-Dynamic-Weighted-Averages-please/m-p/3483780#M133255</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to Power BI and am really hoping for some help. I'm attaching two versions of the PBIX and an Excel showing the general workings that I'm aiming for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.google.com/spreadsheets/d/1daxyqJRyU8AEPl3StNATq-rduCnzzmyT/edit?usp=share_link&amp;amp;ouid=108415431817116777667&amp;amp;rtpof=true&amp;amp;sd=true" target="_self" rel="nofollow noopener noreferrer"&gt;Excel workings&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1nVubiCYy6O5k-oY17jraFmMsboTn54Fr/view?usp=share_link" target="_self" rel="nofollow noopener noreferrer"&gt;PBIX where overall weighted average is correct but it can't rebalance where user applies filters&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1XslppNIOjm4aUkiiyTqkyDHkaiGODu3P/view?usp=share_link" target="_self" rel="nofollow noopener noreferrer"&gt;PBIX where the weight column correctly rebalances when user applies filters, but then weighted avera...&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE: only difference between these two files is the FlexibleGroupWeight measure&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially I have a portfolio with a list of stock weights. There are multiple rows per stock, duplicating the stock weight data. Each unique row is for various metrics on the stocks (ROE, beta etc). For each stock, I need to calculate a weighted average for a metric. When the metric isn't available for a stock, it should automatically rebalance (to 100% in total) the weights for the stocks where the data is available.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Crucially, I'm hoping the weighted average can be dynamic. i.e. when users filter clicking within the dashboard, the weighted average recalculates. So if we filtered to four 5% stocks that total 20% of portfolio, because it's filtered this would all rebalance to 100% and the 5% stocks all become 25% for example.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully you can see what I'm getting at - I've included an Excel workbook to show how I would use SUMIFs to achieve the first of these effects (filtering out and rebalancing stocks based on data availablility).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the Excel shows arrives at the correct aggregate weighted averages for each metric based on the sum of [RebalancedWeight]*[Value] rows for a metric. You can see these correct weighted averages in Column I.&lt;/P&gt;&lt;P&gt;In the Power BI reports, it hinges on the "FlexibleGroupWeight" measure.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In the first file, everything calculates correctly at the aggregate level, and therefore produces correct weighted average metrics ("WA-Metric" column). HOWEVER - &lt;STRONG&gt;it cannot handle user-applied filters (the measure is only using ALLEXCEPT)&lt;/STRONG&gt;.&lt;/LI&gt;&lt;LI&gt;In the second PBIX, the &lt;STRONG&gt;"FlexibleGroupWeight" measure can handle the user-filtering process&lt;/STRONG&gt;.. You click the pie chart to filter on a particular sector, and the number in the first column correctly drops to just the % of the portfolio we are filtered to. The rebalancing &lt;STRONG&gt;&lt;EM&gt;should&lt;/EM&gt; &lt;/STRONG&gt;then work off this smaller total to do a weighted average in that sector only. However - suddenly the actual weighted average metrics are WAY out and it looks as though they become the sum of all the individual stock metric values..&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In latter case my measure uses ALLSELECTED whereas first case uses ALLEXCEPT... Is there some way of combining these two formulas please to get the desired effect? I think that it what would finally get me there!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANK YOU SO SO MUCH IN ADVANCE FOR ANY HELP!!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 15:56:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/REALLY-hoping-for-some-help-on-Dynamic-Weighted-Averages-please/m-p/3483780#M133255</guid>
      <dc:creator>jmillsjmills</dc:creator>
      <dc:date>2023-10-18T15:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: REALLY hoping for some help on Dynamic Weighted Averages please</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/REALLY-hoping-for-some-help-on-Dynamic-Weighted-Averages-please/m-p/3484744#M133318</link>
      <description>&lt;P&gt;It seems like you're working on a complex scenario in Power BI, where you want to calculate dynamic weighted averages for various metrics, and you want these calculations to adapt when users apply filters to the data. I'll try to provide some guidance on how you can achieve this.&lt;/P&gt;&lt;P&gt;In your description, you mentioned two Power BI files, one using the "ALLEXCEPT" function and the other using "ALLSELECTED." Let's combine these two approaches to create a dynamic weighted average that adjusts with user filters.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Data Model Preparation:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Ensure that your data model in Power BI is well-structured with relationships between tables and the necessary columns for calculations.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Measures:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;You'll need to create a set of measures to calculate weighted averages for different metrics. For this example, I'll use the "FlexibleGroupWeight" measure and adjust it to handle user filters.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Weighted Average =&lt;BR /&gt;DIVIDE(&lt;BR /&gt;SUMX(&lt;BR /&gt;FILTER(&lt;BR /&gt;ALLSELECTED('StockTable'),&lt;BR /&gt;ISBLANK([MetricValue]) = FALSE&lt;BR /&gt;),&lt;BR /&gt;'StockTable'[Weight] * [MetricValue]&lt;BR /&gt;),&lt;BR /&gt;SUMX(&lt;BR /&gt;FILTER(&lt;BR /&gt;ALLSELECTED('StockTable'),&lt;BR /&gt;ISBLANK([MetricValue]) = FALSE&lt;BR /&gt;),&lt;BR /&gt;'StockTable'[Weight]&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;This measure calculates a weighted average for the selected data after applying user filters while considering only rows where "MetricValue" is not blank.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Visuals:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Use this new "Weighted Average" measure in your visuals to display dynamic weighted averages.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;With this approach, when users apply filters to your data, the "Weighted Average" measure will adapt to the filtered data, and the weighted average calculations will be dynamic. It will also automatically rebalance when some stocks are excluded due to missing data.&lt;/P&gt;&lt;P&gt;Remember to replace 'StockTable' and [MetricValue] with the actual table and column names from your data model.&lt;/P&gt;&lt;P&gt;This approach should help you achieve your desired dynamic weighted average calculations that adapt to user filters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 06:16:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/REALLY-hoping-for-some-help-on-Dynamic-Weighted-Averages-please/m-p/3484744#M133318</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2023-10-19T06:16:50Z</dc:date>
    </item>
  </channel>
</rss>

