<?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 Complex measure not summing correctly in matrix visual, nor by year in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643731#M177799</link>
    <description>&lt;P&gt;Hi, I have a measure (DAX below) that is essentially calculating in-month revenue by subtracting prior month period-to-date revenue from current month period-to-date revenue (unfortunately there is no way around doing it this way). The calculation for each of those period-to-date revenues itself is also somewhat complex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Norm. MTD Earned Rev. = 
VAR PTDHindsightEarnedRev = 
    VAR md = DATE(year(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),month(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),1)

    RETURN

    SUMX('WIP All Periods DB V3',

        VAR actualptdcost = [PTD Cost]
        VAR hindsightrev = calculate(MAX('WIP All Periods DB V3'[Archived Budget Revenue]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=md)
        VAR hindsightcost = calculate(MAX('WIP All Periods DB V3'[Archived Budget Cost]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=md)
        VAR normpctcomplete = DIVIDE(actualptdcost,hindsightcost,0)

        RETURN normpctcomplete * hindsightrev)

VAR PriorMonthPTDHindsightEarnedRev = 
    VAR pmmd = DATE(year(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),month(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),1)

    RETURN

    CALCULATE(
    SUMX('WIP All Periods DB V3',

        VAR pmactualptdcost = [PTD Cost]
        VAR pmhindsightrev = calculate(MAX('WIP All Periods DB V3'[Archived Budget Revenue]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=pmmd)
        VAR pmhindsightcost = calculate(MAX('WIP All Periods DB V3'[Archived Budget Cost]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=pmmd)
        VAR pmnormpctcomplete = DIVIDE(pmactualptdcost,pmhindsightcost,0)

        RETURN pmnormpctcomplete * pmhindsightrev),
    PREVIOUSMONTH('Date'[Date]))


RETURN PTDHindsightEarnedRev - PriorMonthPTDHindsightEarnedRev&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure is returning the expected values by month, but is way off annually, and fails to sum months correctly across a matrix visual. I should mention I do have a date table in the data model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried creating a separate SUMX measure to aggregate the first, but it is not working. The values are way too high.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be appreciated - thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 08 Apr 2025 19:04:12 GMT</pubDate>
    <dc:creator>schaezac</dc:creator>
    <dc:date>2025-04-08T19:04:12Z</dc:date>
    <item>
      <title>Complex measure not summing correctly in matrix visual, nor by year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643731#M177799</link>
      <description>&lt;P&gt;Hi, I have a measure (DAX below) that is essentially calculating in-month revenue by subtracting prior month period-to-date revenue from current month period-to-date revenue (unfortunately there is no way around doing it this way). The calculation for each of those period-to-date revenues itself is also somewhat complex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Norm. MTD Earned Rev. = 
VAR PTDHindsightEarnedRev = 
    VAR md = DATE(year(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),month(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),1)

    RETURN

    SUMX('WIP All Periods DB V3',

        VAR actualptdcost = [PTD Cost]
        VAR hindsightrev = calculate(MAX('WIP All Periods DB V3'[Archived Budget Revenue]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=md)
        VAR hindsightcost = calculate(MAX('WIP All Periods DB V3'[Archived Budget Cost]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=md)
        VAR normpctcomplete = DIVIDE(actualptdcost,hindsightcost,0)

        RETURN normpctcomplete * hindsightrev)

VAR PriorMonthPTDHindsightEarnedRev = 
    VAR pmmd = DATE(year(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),month(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),1)

    RETURN

    CALCULATE(
    SUMX('WIP All Periods DB V3',

        VAR pmactualptdcost = [PTD Cost]
        VAR pmhindsightrev = calculate(MAX('WIP All Periods DB V3'[Archived Budget Revenue]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=pmmd)
        VAR pmhindsightcost = calculate(MAX('WIP All Periods DB V3'[Archived Budget Cost]),ALLEXCEPT('WIP All Periods DB V3','WIP All Periods DB V3'[ProjectID]),'Date'[Date]=pmmd)
        VAR pmnormpctcomplete = DIVIDE(pmactualptdcost,pmhindsightcost,0)

        RETURN pmnormpctcomplete * pmhindsightrev),
    PREVIOUSMONTH('Date'[Date]))


RETURN PTDHindsightEarnedRev - PriorMonthPTDHindsightEarnedRev&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure is returning the expected values by month, but is way off annually, and fails to sum months correctly across a matrix visual. I should mention I do have a date table in the data model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried creating a separate SUMX measure to aggregate the first, but it is not working. The values are way too high.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be appreciated - thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:04:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643731#M177799</guid>
      <dc:creator>schaezac</dc:creator>
      <dc:date>2025-04-08T19:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Complex measure not summing correctly in matrix visual, nor by year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643877#M177802</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1237081" data-lia-user-login="schaezac" class="lia-mention lia-mention-user"&gt;schaezac&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an idea that assumes the visual grain is year/month and the date table contains a column Month Start Date (2024-03-01, 2024-04-01, etc.). If you could provide a sample pbix, it would facilitate testing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Norm. MTD Earned Rev. =
VAR md =
    DATE ( YEAR ( MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] ) ), MONTH ( MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] ) ), 1 )
VAR Table =
    ADDCOLUMNS (
        VALUES ( 'Date'[Month Start Date] ),
        "@PTDHindsightEarnedRev",
            CALCULATE (
                SUMX (
                    'WIP All Periods DB V3',
                    VAR actualptdcost = [PTD Cost]
                    VAR hindsightrev =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Revenue] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR hindsightcost =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Cost] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR normpctcomplete =
                        DIVIDE ( actualptdcost, hindsightcost, 0 )
                    RETURN
                        normpctcomplete * hindsightrev
                )
            ),
        "@PriorMonthPTDHindsightEarnedRev",
            CALCULATE (
                SUMX (
                    'WIP All Periods DB V3',
                    VAR pmactualptdcost = [PTD Cost]
                    VAR pmhindsightrev =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Revenue] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR pmhindsightcost =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Cost] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR pmnormpctcomplete =
                        DIVIDE ( pmactualptdcost, pmhindsightcost, 0 )
                    RETURN
                        pmnormpctcomplete * pmhindsightrev
                ),
                DATEADD ( 'Date'[Date], -1, MONTH )
            )
    )
VAR Result =
    SUMX ( Table, [@PTDHindsightEarnedRev] - [@PriorMonthPTDHindsightEarnedRev] )
RETURN
    Result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:43:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643877#M177802</guid>
      <dc:creator>DataInsights</dc:creator>
      <dc:date>2025-04-08T20:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Complex measure not summing correctly in matrix visual, nor by year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643895#M177803</link>
      <description>&lt;P&gt;Thanks for your help - I'm getting the following error. I will try to create a sample pbix tomorrow morning (will have to create it from scratch)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The syntax for 'Table' is incorrect. (DAX(VAR md = DATE ( YEAR ( MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] ) ), MONTH ( MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] ) ), 1 )VAR Table = ADDCOLUMNS ( VALUES ( 'Date'[Month Start Date] ), "@PTDHindsightEarnedRev", CALCULATE ( SUMX ( 'WIP All Periods DB V3', VAR actualptdcost = [PTD Cost] VAR hindsightrev = CALCULATE ( MAX ( 'WIP All Periods DB V3'[Archived Budget Revenue] ), ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] ) ) VAR hindsightcost = CALCULATE ( MAX ( 'WIP All Periods DB V3'[Archived Budget Cost] ), ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] ) ) VAR normpctcomplete = DIVIDE ( actualptdcost, hindsightcost, 0 ) RETURN normpctcomplete * hindsightrev ) ), "@PriorMonthPTDHindsightEarnedRev", CALCULATE ( SUMX ( 'WIP All Periods DB V3', VAR pmactualptdcost = [PTD Cost] VAR pmhindsightrev = CALCULATE ( MAX ( 'WIP All Periods DB V3'[Archived Budget Revenue] ), ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] ) ) VAR pmhindsightcost = CALCULATE ( MAX ( 'WIP All Periods DB V3'[Archived Budget Cost] ), ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] ) ) VAR pmnormpctcomplete = DIVIDE ( pmactualptdcost, pmhindsightcost, 0 ) RETURN pmnormpctcomplete * pmhindsightrev ), DATEADD ( 'Date'[Date], -1, MONTH ) ) )VAR Result = SUMX ( Table, [@PTDHindsightEarnedRev] - [@PriorMonthPTDHindsightEarnedRev] )RETURN Result)).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 21:01:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643895#M177803</guid>
      <dc:creator>schaezac</dc:creator>
      <dc:date>2025-04-08T21:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Complex measure not summing correctly in matrix visual, nor by year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643903#M177805</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1237081" data-lia-user-login="schaezac" class="lia-mention lia-mention-user"&gt;schaezac&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easy fix--"Table" is a reserved word so I renamed my variable. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Norm. MTD Earned Rev. =
VAR md =
    DATE ( YEAR ( MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] ) ), MONTH ( MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] ) ), 1 )
VAR RevTable =
    ADDCOLUMNS (
        VALUES ( 'Date'[Month Start Date] ),
        "@PTDHindsightEarnedRev",
            CALCULATE (
                SUMX (
                    'WIP All Periods DB V3',
                    VAR actualptdcost = [PTD Cost]
                    VAR hindsightrev =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Revenue] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR hindsightcost =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Cost] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR normpctcomplete =
                        DIVIDE ( actualptdcost, hindsightcost, 0 )
                    RETURN
                        normpctcomplete * hindsightrev
                )
            ),
        "@PriorMonthPTDHindsightEarnedRev",
            CALCULATE (
                SUMX (
                    'WIP All Periods DB V3',
                    VAR pmactualptdcost = [PTD Cost]
                    VAR pmhindsightrev =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Revenue] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR pmhindsightcost =
                        CALCULATE (
                            MAX ( 'WIP All Periods DB V3'[Archived Budget Cost] ),
                            ALLEXCEPT ( 'WIP All Periods DB V3', 'WIP All Periods DB V3'[ProjectID] )
                        )
                    VAR pmnormpctcomplete =
                        DIVIDE ( pmactualptdcost, pmhindsightcost, 0 )
                    RETURN
                        pmnormpctcomplete * pmhindsightrev
                ),
                DATEADD ( 'Date'[Date], -1, MONTH )
            )
    )
VAR Result =
    SUMX ( RevTable, [@PTDHindsightEarnedRev] - [@PriorMonthPTDHindsightEarnedRev] )
RETURN
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Apr 2025 21:14:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643903#M177805</guid>
      <dc:creator>DataInsights</dc:creator>
      <dc:date>2025-04-08T21:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Complex measure not summing correctly in matrix visual, nor by year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643910#M177806</link>
      <description>&lt;P&gt;Amazing. Works perfectly and I learned a whole new approach to this. THANK YOU!!!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 21:26:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643910#M177806</guid>
      <dc:creator>schaezac</dc:creator>
      <dc:date>2025-04-08T21:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Complex measure not summing correctly in matrix visual, nor by year</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643914#M177807</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1237081" data-lia-user-login="schaezac" class="lia-mention lia-mention-user"&gt;schaezac&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to hear it works! ADDCOLUMNS is a powerful function and an important tool in the toolkit.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 21:33:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Complex-measure-not-summing-correctly-in-matrix-visual-nor-by/m-p/4643914#M177807</guid>
      <dc:creator>DataInsights</dc:creator>
      <dc:date>2025-04-08T21:33:07Z</dc:date>
    </item>
  </channel>
</rss>

