<?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 Re: AVERAGEX after using IF Statement in Power BI in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3508213#M134599</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp; , Please can you help us in this issue ? thank you in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2023 21:00:46 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-10-31T21:00:46Z</dc:date>
    <item>
      <title>AVERAGEX after using IF Statement in Power BI</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3503481#M134376</link>
      <description>&lt;P&gt;Hi everyone !&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, I have this Problem and I need your help to solve it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; Sales table with relation to Date Dim table&amp;nbsp; , one filter is the year&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;this is &lt;A href="https://www.dropbox.com/scl/fi/qj0spr403xzlbffpf2yus/averagex-after-using-if-statement-power-bi.pbix?rlkey=0jlewf4bqqc2lv2ajtd465ctx&amp;amp;dl=0" target="_self"&gt;&lt;STRONG&gt;&lt;EM&gt;pbix file&amp;nbsp;↓&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I calculated the Current year Sales and Current year Quantity&amp;nbsp; and average Price of current year &amp;nbsp;and the totals are good&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;CYSALES = (SUM(Sales[netValue]))&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;CYQTY = (SUM(Sales[Qty]))&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;AVG Price CYSales = AVERAGEX(SUMMARIZE(Sales,Sales[CustomerNumber ],Sales[PartNumber]),[CYSALES]/[CYQTY])&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;with the same logic I calculated the Previous year Sales and Previous year Quantity and average Price of previous year&amp;nbsp; and the totals are good&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;PYQTY&amp;nbsp; &amp;nbsp;// Previous year Quantity&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;PYSALES&amp;nbsp; // Previous year sales&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;EM&gt;AVG Price PYSales =PYSALES /PYQTY&amp;nbsp; &amp;nbsp;&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I have a condition for&amp;nbsp;AVG Price CYSales,&amp;nbsp; IF (AVG Price CYSales) is blank&amp;nbsp; replace it by&amp;nbsp;AVG Price PYSales&amp;nbsp; // if current year value is blank replace it by the previous year value&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and for&amp;nbsp;AVG Price PYSales , IF (AVG Price PYSales) is blank&amp;nbsp; replace it by&amp;nbsp;AVG Price CYSales&amp;nbsp;// if previous year value is blank replace it by the current&amp;nbsp; year value&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FOR THIS ,I created two new measures&amp;nbsp; :&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the result on the report&amp;nbsp; :&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I want the Averagex totals correct !!!! like on Excel file&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please I need your help !!&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 Oct 2023 16:06:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3503481#M134376</guid>
      <dc:creator>Itachi_Utchiha</dc:creator>
      <dc:date>2023-10-30T16:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: AVERAGEX after using IF Statement in Power BI</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3503833#M134408</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;here is the workaround (this shows up in muliple other posts).&lt;BR /&gt;Let's assume a table&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Col is thie the original numbers. As soon as blanks come into play, the total of the Col columns is not shown, although formatted as number and not even with blanks. When I wrap the column everything is fine.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be honest, I refuse to think about, why this is happening. I just apply the workaround for my conditional average as well:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;So, lesson: if the visual is showing unintuitive stuff, try to find wrapper measures, where you control the outcome in the rows and in the totals.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&amp;nbsp;&lt;BR /&gt;Christian&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 06:20:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3503833#M134408</guid>
      <dc:creator>scee07</dc:creator>
      <dc:date>2023-10-30T06:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: AVERAGEX after using IF Statement in Power BI</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3507493#M134563</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="97900" data-lia-user-login="scee07" class="lia-mention lia-mention-user"&gt;scee07&lt;/a&gt;&amp;nbsp;, thank you so much for your response !&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried it but still not working !! I attached the Pbix file to the question ! I'll be so grateful if you can help !&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards .&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 14:54:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3507493#M134563</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-10-31T14:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: AVERAGEX after using IF Statement in Power BI</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3508213#M134599</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp; , Please can you help us in this issue ? thank you in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 21:00:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3508213#M134599</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-10-31T21:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: AVERAGEX after using IF Statement in Power BI</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3509572#M134660</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I will do some calculated columsn for my solution proposal. This can always be translated to a complete measure approach as need be. I will pick one of your measures to explain my approach.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;First of all, if you calculate averages just make sure what you want. Your example shows the average of the prices. This is different to the weighted average price (Total Net Value)/ (Total Units). If this is what you want, fine.&lt;BR /&gt;&lt;BR /&gt;The other issue is that if you use summarize in your calculation, definitely all combinations that have no sales in the filtered year will not be there. So the combination year/product/part will have no context for the total and is missing.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If this is true, all combination where want to have values must be created:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SalesTmp =
CROSSJOIN (
    VALUES ( dateDim[year] ),
    VALUES ( Sales[CustomerNumber ] ),
    VALUES ( Sales[PartNumber] )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then we do calculated columns to replace blanks with values.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TotalNetValue =
VAR thisYear = SalesTmp[year]
VAR thisCustomer = SalesTmp[CustomerNumber ]
VAR thisPart = SalesTmp[PartNumber]
VAR prevYear = thisYear - 1
VAR nxtYear = thisYear + 1
VAR netValueThisYear =
    CALCULATE (
        SUM ( Sales[netValue] ),
        FILTER (
            Sales,
            YEAR ( Sales[Invoice date] ) = thisYear
                &amp;amp;&amp;amp; Sales[CustomerNumber ] = thisCustomer
                &amp;amp;&amp;amp; Sales[PartNumber] = thisPart
        )
    )
VAR netValueLastYear =
    CALCULATE (
        SUM ( Sales[netValue] ),
        FILTER (
            Sales,
            YEAR ( Sales[Invoice date] ) = prevYear
                &amp;amp;&amp;amp; Sales[CustomerNumber ] = thisCustomer
                &amp;amp;&amp;amp; Sales[PartNumber] = thisPart
        )
    )
VAR netValueNextYear =
    CALCULATE (
        SUM ( Sales[netValue] ),
        FILTER (
            Sales,
            YEAR ( Sales[Invoice date] ) = nxtYear
                &amp;amp;&amp;amp; Sales[CustomerNumber ] = thisCustomer
                &amp;amp;&amp;amp; Sales[PartNumber] = thisPart
        )
    )
RETURN
    IF (
        NOT ISBLANK ( netValueThisYear ),
        netValueThisYear,
        IF ( NOT ISBLANK ( netValueLastYear ), netValueLastYear, netValueNextYear )
    )

TotalQty =
VAR thisYear = SalesTmp[year]
VAR thisCustomer = SalesTmp[CustomerNumber ]
VAR thisPart = SalesTmp[PartNumber]
VAR prevYear = thisYear - 1
VAR nxtYear = thisYear + 1
VAR netValueThisYear =
    CALCULATE (
        SUM ( Sales[Qty] ),
        FILTER (
            Sales,
            YEAR ( Sales[Invoice date] ) = thisYear
                &amp;amp;&amp;amp; Sales[CustomerNumber ] = thisCustomer
                &amp;amp;&amp;amp; Sales[PartNumber] = thisPart
        )
    )
VAR netValueLastYear =
    CALCULATE (
        SUM ( Sales[Qty] ),
        FILTER (
            Sales,
            YEAR ( Sales[Invoice date] ) = prevYear
                &amp;amp;&amp;amp; Sales[CustomerNumber ] = thisCustomer
                &amp;amp;&amp;amp; Sales[PartNumber] = thisPart
        )
    )
VAR netValueNextYear =
    CALCULATE (
        SUM ( Sales[Qty] ),
        FILTER (
            Sales,
            YEAR ( Sales[Invoice date] ) = nxtYear
                &amp;amp;&amp;amp; Sales[CustomerNumber ] = thisCustomer
                &amp;amp;&amp;amp; Sales[PartNumber] = thisPart
        )
    )
RETURN
    IF (
        NOT ISBLANK ( netValueThisYear ),
        netValueThisYear,
        IF ( NOT ISBLANK ( netValueLastYear ), netValueLastYear, netValueNextYear )
    )

Price =
SalesTmp[TotalNetValue] / SalesTmp[TotalQty]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, you replacement logic should be incorporated. Might be that your rules are different. This is to check.&lt;BR /&gt;You now have the price per line.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that you have a full table without blanks here.&amp;nbsp;&lt;BR /&gt;As mentioned above, you can take the average in two different ways:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;WeightedPrice =
[TotalNetValueM] / [TotalQtyM]

PriceM =
AVERAGE ( SalesTmp[Price] )
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Here, your average requirement is satisfied (PriceM measure).&amp;nbsp;&lt;BR /&gt;Some remarks:&lt;BR /&gt;- you have presumably read that calculated columns are bad and to be avoided. If you have big tables and not enough memory space, this might be true.&lt;/P&gt;&lt;P&gt;- however, there is no free lunch. Here, some calculations are done before visualisation, which means that the visual rendering will be quicker. The resulting measures above are super simple.&amp;nbsp;&lt;BR /&gt;- There are lot of DAX commands that do some filter context artistery. If it is getting too complex, I have my problems debugging that. The more gifted might be OK with that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;- As you have seen yourself complex depenencies of measures and filters can get very confusing.&lt;BR /&gt;&lt;BR /&gt;What at least I learned from all that:&lt;BR /&gt;- if the model is small., I do calculated columns. In this manner I have control over immediate steps and I can see better what is going on&lt;/P&gt;&lt;P&gt;- If needed, this can be translated into measures&lt;BR /&gt;&lt;BR /&gt;All a matter of taste and depending on the specifics of the situation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Christian&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 12:40:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AVERAGEX-after-using-IF-Statement-in-Power-BI/m-p/3509572#M134660</guid>
      <dc:creator>scee07</dc:creator>
      <dc:date>2023-11-01T12:40:06Z</dc:date>
    </item>
  </channel>
</rss>

