<?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: Unable to get the YTD number for a given total in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4706273#M180240</link>
    <description>&lt;P&gt;I've used the below function to work out a summarized table. In a nutshell, this code creates 2 separate tables, one for P&amp;amp;L where I need the amounts monthly and one for Balance sheet where I just need the number as is and then using "Union()", I've combined the two tables together. This is working for me now thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Summarized TB = 
VAR PL =
SUMMARIZECOLUMNS(
    COA_Grouping[P&amp;amp;L/ BS]
    , COA_Grouping[GL]
    , COA_Grouping[GL Description]
    , 'Cost Centre'[Cost Centre]
    , 'Calendar'[Date]
    , FILTER(
        COA_Grouping
        , COA_Grouping[P&amp;amp;L/ BS] = "P&amp;amp;L"
    )
    , "Ending Balance", SUM('OS TB_Input'[Amount])
    , "PrevMonth", CALCULATE(
        SUM('OS TB_Input'[Amount])
        , PREVIOUSMONTH('Calendar'[Date])
    )
)

VAR BS =
SUMMARIZECOLUMNS(
    COA_Grouping[P&amp;amp;L/ BS]
    , COA_Grouping[GL]
    , COA_Grouping[GL Description]
    , 'Cost Centre'[Cost Centre]
    , 'Calendar'[Date]
    , FILTER(
        COA_Grouping
        , COA_Grouping[P&amp;amp;L/ BS] = "BS"
    )
    , "Ending Balance", SUM('OS TB_Input'[Amount])
    , "PrevMonth", SUM('OS TB_Input'[Amount])
)

VAR Monthly_PL= 
    ADDCOLUMNS(
        FILTER(
        PL
        , NOT ISBLANK([Ending Balance])
    )
    , "Monthly", [Ending Balance]- [PrevMonth]
)

VAR BS_Final= 
    ADDCOLUMNS(
        FILTER(
        BS
        , NOT ISBLANK([Ending Balance])
    )
    , "Monthly", [Ending Balance]
)
VAR TB_Final = UNION(Monthly_PL, BS_Final)

RETURN TB_Final&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 25 May 2025 14:22:25 GMT</pubDate>
    <dc:creator>kapilg89</dc:creator>
    <dc:date>2025-05-25T14:22:25Z</dc:date>
    <item>
      <title>Unable to get the YTD number for a given total</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4704399#M180180</link>
      <description>&lt;P&gt;I'm working with a trial balance which gives output in YTD format i.e. it rolls up the numbers from Jan to whichever month you are downloading the data for. Now I want to work our the amounts for the month for which I have written the below dax&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my Base data named &lt;U&gt;&lt;STRONG&gt;"OS TB_Input"&lt;/STRONG&gt;&lt;/U&gt; which is granular to the &lt;U&gt;GL&lt;/U&gt; and &lt;U&gt;Cost Centre&lt;/U&gt; and I have a Dimention table for both &lt;U&gt;GL&lt;/U&gt; and &lt;U&gt;Cost centre&lt;/U&gt; separately and mapped to this Fact table along with a &lt;U&gt;Calendar&lt;/U&gt; table mapped to the Month Column.&amp;nbsp;&lt;U&gt;Amount&lt;/U&gt; is the column with YTD numbers for each particular month for that &lt;U&gt;GL/ Cost Centre.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;"[Trial Balance]" just sums up the amount column which is YTD numbers.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Trial Balance = SUM('OS TB_Input'[Amount])&lt;/LI-CODE&gt;&lt;P&gt;Monthly is a measure created to find the monthly values&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Monthly = 
VAR PrevMonth = 
    CALCULATE(
        [Trial Balance],
        PREVIOUSMONTH('Calendar'[Date]),
        COA_Grouping[P&amp;amp;L/ BS] = "P&amp;amp;L"
    )
VAR CurrentMonth = 
    CALCULATE(
        [Trial Balance],
        COA_Grouping[P&amp;amp;L/ BS] = "P&amp;amp;L"
    )

RETURN
IF(
    ISBLANK(CurrentMonth),
    BLANK(),
    [Trial Balance]- PrevMonth
)&lt;/LI-CODE&gt;&lt;P&gt;Although this gives the monthly numbers correctly but it messes up the totals as what I expect in the total yearly column is the sum of all the Months whereas it's showing up a much different number.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Pl help to correct the totals and also if someone could suggest how to improve the dax, that would be of great help.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 23 May 2025 04:18:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4704399#M180180</guid>
      <dc:creator>kapilg89</dc:creator>
      <dc:date>2025-05-23T04:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get the YTD number for a given total</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4705337#M180209</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1273723" data-lia-user-login="kapilg89" class="lia-mention lia-mention-user"&gt;kapilg89&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you’ve got access to the GL or TB data at a monthly level (especially from ERPs like SAP or Oracle), you wouldn't need to even bother with this whole YTD-back-to-month wrangling. Just get the monthly values directly from ERP and simplify your life. Transaction lists from ERP are also excellent source data if you're trying to be precise — they let you rebuild everything bottom-up including TB with more granularity.&lt;/P&gt;
&lt;P&gt;But in the absence of monthly granularity, the SUMX-based DAX trick below is your best bet.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF(ISBLANK(...)) is notorious for messing up totals because BLANK() in row context doesn’t mean the same thing in total context.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here’s a better version that ditches IF and leans on math to behave properly in totals:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Monthly = 
SUMX(
    VALUES('Calendar'[Date]),
    VAR Current =
        CALCULATE(
            [Trial Balance],
            COA_Grouping[P&amp;amp;L/ BS] = "P&amp;amp;L"
        )
    VAR Previous =
        CALCULATE(
            [Trial Balance],
            COA_Grouping[P&amp;amp;L/ BS] = "P&amp;amp;L",
            DATEADD('Calendar'[Date], -1, MONTH)
        )
    RETURN
        Current - COALESCE(Previous, 0)
)
&lt;/LI-CODE&gt;
&lt;P&gt;By using COALESCE, you're making sure that even if the previous value is blank, it doesn’t mess up your logic — it just assumes a 0 instead. No IF, means no total messing up. Just the deltas you expect, with totals that actually add up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 14:05:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4705337#M180209</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2025-05-23T14:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get the YTD number for a given total</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4705392#M180211</link>
      <description>&lt;P&gt;&lt;SPAN data-teams="true"&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1273723" data-lia-user-login="kapilg89" class="lia-mention lia-mention-user"&gt;kapilg89&lt;/a&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN data-teams="true"&gt;The issue arises because the DAX measure that calculates monthly values by subtracting the previous month's YTD amount from the current month's YTD amount works correctly at the individual month level but fails at the total level. In a matrix visual, each row provides the necessary context for PREVIOUSMONTH&amp;nbsp;to return the correct prior month, allowing the formula to calculate accurate month-over-month differences. However, in the total row, there is no specific month context, so the PREVIOUSMONTH&amp;nbsp;function returns blank. As a result, the measure ends up subtracting blank from the current YTD value, effectively displaying the full YTD total again instead of summing the monthly values. This leads to an inflated or misleading total that doesn't represent the actual sum of the monthly changes across the year.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;To resolve the issue you're facing with incorrect totals in your monthly measure, I recommend using a combination of &lt;SPAN data-teams="true"&gt;SUMMARIZE&amp;nbsp;&lt;/SPAN&gt; and &lt;SPAN data-teams="true"&gt;SUMX&lt;/SPAN&gt; in your DAX formula. The key idea is to avoid relying on the visual’s row context, which works fine for individual months but fails at the total level due to how &lt;SPAN data-teams="true"&gt;PREVIOUSMONTH&lt;/SPAN&gt;&amp;nbsp;behaves. Instead, use &lt;SPAN data-teams="true"&gt;SUMMARIZE&lt;/SPAN&gt;&amp;nbsp;to create a virtual table that explicitly lists each distinct month. For each of these months, calculate the monthly value as the difference between the current month's YTD and the previous month's YTD. Then, use &lt;SPAN data-teams="true"&gt;SUMX&lt;/SPAN&gt; to iterate over this table and sum the individual monthly values. This approach ensures that your measure returns accurate monthly figures in both detailed and total views, preventing the total from incorrectly showing the final YTD value instead of the sum of monthly changes.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN data-teams="true"&gt;I hope this helped! Feel free to ask any further questions. If this resolved your issue, please mark it as "Accept as Solution" and give us Kudos to assist others.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;SPAN data-teams="true"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 14:34:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4705392#M180211</guid>
      <dc:creator>v-sgandrathi</dc:creator>
      <dc:date>2025-05-23T14:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get the YTD number for a given total</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4706273#M180240</link>
      <description>&lt;P&gt;I've used the below function to work out a summarized table. In a nutshell, this code creates 2 separate tables, one for P&amp;amp;L where I need the amounts monthly and one for Balance sheet where I just need the number as is and then using "Union()", I've combined the two tables together. This is working for me now thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Summarized TB = 
VAR PL =
SUMMARIZECOLUMNS(
    COA_Grouping[P&amp;amp;L/ BS]
    , COA_Grouping[GL]
    , COA_Grouping[GL Description]
    , 'Cost Centre'[Cost Centre]
    , 'Calendar'[Date]
    , FILTER(
        COA_Grouping
        , COA_Grouping[P&amp;amp;L/ BS] = "P&amp;amp;L"
    )
    , "Ending Balance", SUM('OS TB_Input'[Amount])
    , "PrevMonth", CALCULATE(
        SUM('OS TB_Input'[Amount])
        , PREVIOUSMONTH('Calendar'[Date])
    )
)

VAR BS =
SUMMARIZECOLUMNS(
    COA_Grouping[P&amp;amp;L/ BS]
    , COA_Grouping[GL]
    , COA_Grouping[GL Description]
    , 'Cost Centre'[Cost Centre]
    , 'Calendar'[Date]
    , FILTER(
        COA_Grouping
        , COA_Grouping[P&amp;amp;L/ BS] = "BS"
    )
    , "Ending Balance", SUM('OS TB_Input'[Amount])
    , "PrevMonth", SUM('OS TB_Input'[Amount])
)

VAR Monthly_PL= 
    ADDCOLUMNS(
        FILTER(
        PL
        , NOT ISBLANK([Ending Balance])
    )
    , "Monthly", [Ending Balance]- [PrevMonth]
)

VAR BS_Final= 
    ADDCOLUMNS(
        FILTER(
        BS
        , NOT ISBLANK([Ending Balance])
    )
    , "Monthly", [Ending Balance]
)
VAR TB_Final = UNION(Monthly_PL, BS_Final)

RETURN TB_Final&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 14:22:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Unable-to-get-the-YTD-number-for-a-given-total/m-p/4706273#M180240</guid>
      <dc:creator>kapilg89</dc:creator>
      <dc:date>2025-05-25T14:22:25Z</dc:date>
    </item>
  </channel>
</rss>

