<?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: Weekly closingBlance by AccountNo with missing WeekEndDate in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3579349#M138039</link>
    <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="403667" data-lia-user-login="123abc" class="lia-mention lia-mention-user"&gt;123abc&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;First of all, thank your for your input and thougt ! In the meantime, I found these formulas that get me the closing Balance of&amp;nbsp; each Week.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FirstOpeningBalance = 
IF('Positions et mouvements bancaires réels'[RowID] = CALCULATE(MIN('Positions et mouvements bancaires réels'[RowID]), ALLEXCEPT('Positions et mouvements bancaires réels', 'Positions et mouvements bancaires réels'[Accounting No], 'Mapping Entity'[Entity/BU], 'Mapping Entity'[Country])), 'Positions et mouvements bancaires réels'[Closing Balance])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;ClosingWeeklyBalance = 
VAR _last_visible_date = MAX('Date'[Week End  Date])
VAR _first_visible_date = MIN('Date'[Week End  Date])
VAR _last_noblank_date = CALCULATE(MAX('Positions et mouvements bancaires réels'[Accounting Date]), REMOVEFILTERS())

VAR _result = 
    IF(
        _first_visible_date &amp;lt;= _last_noblank_date,
        CALCULATE(
            SUM('Positions et mouvements bancaires réels'[Sum_Amount ]),
            'Date'[Week End  Date] &amp;lt;= _last_visible_date,
            ALLEXCEPT(
                'Positions et mouvements bancaires réels', 
                'Positions et mouvements bancaires réels'[Accounting No],
                'Mapping Entity'[Entity/BU], 'Mapping comptes'[Accounting No]
            ),
            'Positions et mouvements bancaires réels'[StartsWith5] = "TRUE"
        ) + CALCULATE(
            SUM('Positions et mouvements bancaires réels'[FirstOpeningBalance]),
            ALLEXCEPT(
                'Positions et mouvements bancaires réels', 
                'Positions et mouvements bancaires réels'[Accounting No],
                'Mapping Entity'[Entity/BU], 'Mapping comptes'[Accounting No]
            ),
            'Positions et mouvements bancaires réels'[StartsWith5] = "TRUE"
        )
    )

RETURN _result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I think I may be more performant than creating a crossJoin table. But now I still struggle to do the same thing to get the OpeningBalance. The ClosingBalance of a week should be the Opening Balance of the following week. If you have ideas about how I can simply do that in Dax I would glady take your ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2023 09:04:14 GMT</pubDate>
    <dc:creator>og_gremlins</dc:creator>
    <dc:date>2023-12-12T09:04:14Z</dc:date>
    <item>
      <title>Weekly closingBlance by AccountNo with missing WeekEndDate</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3577923#M137973</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I need help in generating a matrix/bar chart with weekly closing balance.&lt;/P&gt;&lt;P&gt;I have two datasets :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;Position&lt;/LI&gt;&lt;LI&gt;Date&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Date has been created based on "AccountingDate" of Position table. I added a column "WeekEndDate" which is the end date of each week.&lt;/P&gt;&lt;P&gt;I tried to get the last BalanceValue for each "AccountNo" at the end of the week. The problem is that sometimes, AccountNo has no record in a week. Thus value in matrix is wrong. Here is an example :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my WeekEndDate is 14/01/22, final week balance should be : 95808,99 + (-1646984,4056) + 91288,25 = &lt;STRONG&gt;-1459887,17&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But in my matrix Balance of AccountNo 512411 was not took in the measure. Hence It returns :&amp;nbsp; (-1646984,4056) + 91288,25 = &lt;STRONG&gt;-1555696,16&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently use this method I found from another forum and tuned it with my dataset :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;lastnonblankdate =

LASTNONBLANK ( 'Positions et mouvements bancaires réels'[Accounting Date], CALCULATE ( SUM ( 'Positions et mouvements bancaires réels'[BalanceDaily] ) ) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;lastnonblankvaue by category: =

VAR _lastnonblankdatebycategory =

    ADDCOLUMNS (

        SUMMARIZE ( 'Positions et mouvements bancaires réels', 'Mapping comptes'[Accounting No] ),

        "@lastnonblankdate", [lastnonblankdate]

    )

RETURN

    IF (

        HASONEVALUE ('Date'[Week End  Date]),

        CALCULATE (

            SUM ( 'Positions et mouvements bancaires réels'[BalanceDaily] ),

            TREATAS (

                _lastnonblankdatebycategory,

                'Mapping comptes'[Accounting No],

                'Date'[Date]

            )

        )

    )&lt;/LI-CODE&gt;&lt;P&gt;Do somoes ever faced this issue and came up with an alternative or solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2023 15:48:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3577923#M137973</guid>
      <dc:creator>og_gremlins</dc:creator>
      <dc:date>2023-12-11T15:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Weekly closingBlance by AccountNo with missing WeekEndDate</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3578949#M138025</link>
      <description>&lt;P&gt;It looks like you are dealing with a scenario where you want to calculate the closing balance for each account at the end of each week, considering weeks where there might be no transactions for some accounts. Your current DAX formula attempts to find the last non-blank date for each account and then calculates the sum of daily balances for that date.&lt;/P&gt;&lt;P&gt;To handle cases where an account has no record in a week, you might need to modify your approach. One way to achieve this is to create a table or a measure that contains all possible combinations of AccountNo and WeekEndDate, and then use that as a basis for your calculations.&lt;/P&gt;&lt;P&gt;Here's an example of how you could modify your DAX formula:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Create a Calendar Table:&lt;/STRONG&gt; Make sure you have a calendar table that includes all the dates in your dataset.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Create a CrossJoin Table:&lt;/STRONG&gt; Create a new table or a calculated table that represents all possible combinations of AccountNo and WeekEndDate. You can use CROSSJOIN or other techniques to achieve this.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;CrossJoinTable = CROSSJOIN('Mapping comptes', 'Date')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Modify your DAX formula:&lt;/STRONG&gt;&lt;SPAN&gt; Use the new CrossJoinTable to calculate the closing balance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ClosingBalance =&lt;BR /&gt;CALCULATE (&lt;BR /&gt;SUM ( 'Positions et mouvements bancaires réels'[BalanceDaily] ),&lt;BR /&gt;FILTER (&lt;BR /&gt;CrossJoinTable,&lt;BR /&gt;'Positions et mouvements bancaires réels'[Accounting No] = 'Mapping comptes'[Accounting No]&lt;BR /&gt;&amp;amp;&amp;amp; 'Date'[Date] &amp;lt;= 'Date'[Week End Date]&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This modification ensures that you are considering all combinations of AccountNo and WeekEndDate, even if there are no records for a particular combination.&lt;/P&gt;&lt;P&gt;Remember to adjust the table and column names according to your actual dataset structure. Additionally, performance considerations should be taken into account, especially if your dataset is large. If performance becomes an issue, you might need to optimize the model or consider using alternate approaches such as creating relationships between tables.&lt;/P&gt;&lt;P&gt;Please adapt the code according to your data model and relationships. If you have specific details about your data structure, I can provide more tailored guidance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&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;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 05:21:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3578949#M138025</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2023-12-12T05:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Weekly closingBlance by AccountNo with missing WeekEndDate</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3579349#M138039</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="403667" data-lia-user-login="123abc" class="lia-mention lia-mention-user"&gt;123abc&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;First of all, thank your for your input and thougt ! In the meantime, I found these formulas that get me the closing Balance of&amp;nbsp; each Week.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FirstOpeningBalance = 
IF('Positions et mouvements bancaires réels'[RowID] = CALCULATE(MIN('Positions et mouvements bancaires réels'[RowID]), ALLEXCEPT('Positions et mouvements bancaires réels', 'Positions et mouvements bancaires réels'[Accounting No], 'Mapping Entity'[Entity/BU], 'Mapping Entity'[Country])), 'Positions et mouvements bancaires réels'[Closing Balance])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;ClosingWeeklyBalance = 
VAR _last_visible_date = MAX('Date'[Week End  Date])
VAR _first_visible_date = MIN('Date'[Week End  Date])
VAR _last_noblank_date = CALCULATE(MAX('Positions et mouvements bancaires réels'[Accounting Date]), REMOVEFILTERS())

VAR _result = 
    IF(
        _first_visible_date &amp;lt;= _last_noblank_date,
        CALCULATE(
            SUM('Positions et mouvements bancaires réels'[Sum_Amount ]),
            'Date'[Week End  Date] &amp;lt;= _last_visible_date,
            ALLEXCEPT(
                'Positions et mouvements bancaires réels', 
                'Positions et mouvements bancaires réels'[Accounting No],
                'Mapping Entity'[Entity/BU], 'Mapping comptes'[Accounting No]
            ),
            'Positions et mouvements bancaires réels'[StartsWith5] = "TRUE"
        ) + CALCULATE(
            SUM('Positions et mouvements bancaires réels'[FirstOpeningBalance]),
            ALLEXCEPT(
                'Positions et mouvements bancaires réels', 
                'Positions et mouvements bancaires réels'[Accounting No],
                'Mapping Entity'[Entity/BU], 'Mapping comptes'[Accounting No]
            ),
            'Positions et mouvements bancaires réels'[StartsWith5] = "TRUE"
        )
    )

RETURN _result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I think I may be more performant than creating a crossJoin table. But now I still struggle to do the same thing to get the OpeningBalance. The ClosingBalance of a week should be the Opening Balance of the following week. If you have ideas about how I can simply do that in Dax I would glady take your ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 09:04:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3579349#M138039</guid>
      <dc:creator>og_gremlins</dc:creator>
      <dc:date>2023-12-12T09:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Weekly closingBlance by AccountNo with missing WeekEndDate</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3579371#M138040</link>
      <description>&lt;P&gt;NB: I found a trick, soustracting 7 to last visible date ^^. Thanks again&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 09:18:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weekly-closingBlance-by-AccountNo-with-missing-WeekEndDate/m-p/3579371#M138040</guid>
      <dc:creator>og_gremlins</dc:creator>
      <dc:date>2023-12-12T09:18:37Z</dc:date>
    </item>
  </channel>
</rss>

