<?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: Add custom Row based on Dax logic in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4299045#M170717</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="405743" data-lia-user-login="Puja" class="lia-mention lia-mention-user"&gt;Puja&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To accomplish this in DAX, you need to create a calculated table or use measures to dynamically calculate the new row based on the provided logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Solution Using a Calculated Table&lt;/STRONG&gt;&lt;/H3&gt;&lt;LI-CODE lang="markup"&gt;EnhancedTable = 
UNION(
    'OriginalTable', -- Keep all original rows
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER('OriginalTable', 'OriginalTable'[Type] IN {"Wages - Temp Staff", "Payroll Tax Temp"}),
            'OriginalTable'[ID]
        ),
        "Type", "Asset Purchases",
        "Value", 
            (CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Wages - Temp Staff") + 
            CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Payroll Tax Temp")) * -1
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Solution Using a Measure&lt;/STRONG&gt; (If no new rows are required)&lt;/H3&gt;&lt;P&gt;If you want to dynamically calculate the value for "Asset Purchases" in visuals (like a table), use a measure:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Asset Purchases = 
VAR TempStaffValue = 
    CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Wages - Temp Staff")
VAR PayrollTaxValue = 
    CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Payroll Tax Temp")
RETURN
(TempStaffValue + PayrollTaxValue) * -1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Did I answer your question? Mark my post as a solution, this will help others!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If my response(s) assisted you in any way, don't forget to drop me a "&lt;STRONG&gt;Kudos&lt;/STRONG&gt;" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Poojara&lt;BR /&gt;Data Analyst | MSBI Developer | Power BI Consultant&lt;BR /&gt;&lt;STRONG&gt;Please Subscribe my YouTube for Beginners/Advance Concepts:&lt;/STRONG&gt;&amp;nbsp;&lt;A href="https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS" target="_self"&gt;https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Nov 2024 04:46:54 GMT</pubDate>
    <dc:creator>Poojara_D12</dc:creator>
    <dc:date>2024-11-25T04:46:54Z</dc:date>
    <item>
      <title>Add custom Row based on Dax logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4297846#M170658</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I need some help with Dax. The data is grouped by ID. In Type column, the highlighed rows are need to build based om the logic.&lt;/P&gt;&lt;P&gt;Ex: Asset Purchases , add a row by adding above 2 rows ((Wages-Temp Staff +Payroll Tax Temp) *-1 ) then create a new row which is "Asset Purchases"&lt;/P&gt;&lt;P&gt;FYI,&amp;nbsp;Asset Purchases is not from dataset.&lt;/P&gt;&lt;P&gt;&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;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 21:05:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4297846#M170658</guid>
      <dc:creator>Puja</dc:creator>
      <dc:date>2024-11-22T21:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Add custom Row based on Dax logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4298009#M170666</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="405743" data-lia-user-login="Puja" class="lia-mention lia-mention-user"&gt;Puja&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you trying to create bookkeeping journal entries with debits and credits that balance to zero? If so, I recommend using Power Query to generate double-entry bookkeeping records. DAX is not ideal for this task, but Power Query excels at creating structured double-entry bookkeeping entries. I use it for this purpose regularly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here’s how you can do it:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Process in Power Query:&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;Start with your transaction data table.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Create a custom column named "Asset Purchases" that calculates the value based on your formula:&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;LI-CODE lang="markup"&gt;("Wages - Temp Staff" + "Payroll Tax Temp") * -1
&lt;/LI-CODE&gt;
&lt;OL&gt;
&lt;LI&gt;Unpivot the columns so that you have the debits and credits structured in rows.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Below is the Power Query M code for this process:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;
let
    // Load your transaction data
    Source = Table.FromRows(
        {
            {"ID001", "Wages - Temp Staff", 1000},
            {"ID001", "Payroll Tax Temp", 200},
            {"ID002", "Wages - Temp Staff", 1500},
            {"ID002", "Payroll Tax Temp", 300}
        },
        {"ID", "Type", "Value"}
    ),
    
    // Group the data by ID
    GroupedData = Table.Group(
        Source, 
        {"ID"}, 
        {
            {"AllData", each _, type table [ID=nullable text, Type=nullable text, Value=nullable number]}
        }
    ),

    // Add a custom row for "Asset Purchases" based on the logic
    AddAssetPurchases = Table.TransformColumns(
        GroupedData, 
        {"AllData", each Table.Combine({
            _,
            Table.FromRows(
                {{[ID = List.First(_[ID]), Type = "Asset Purchases", Value = ([Value]{0} + [Value]{1}) * -1]}},
                Table.Type(_)
            )
        })}
    ),

    // Expand the grouped data back to a flat table
    ExpandedData = Table.ExpandTableColumn(AddAssetPurchases, "AllData", {"ID", "Type", "Value"}),

    // Unpivot if required (for debit/credit separation)
    UnpivotedData = Table.UnpivotOtherColumns(ExpandedData, {"ID", "Type"}, "Attribute", "Value")
    
in
    UnpivotedData
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;This method ensures your bookkeeping entries balance to zero by automatically generating the corresponding "Asset Purchases" entry and formatting the data appropriately. Let me know if you need further assistance!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2024 04:32:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4298009#M170666</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2024-11-23T04:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Add custom Row based on Dax logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4299045#M170717</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="405743" data-lia-user-login="Puja" class="lia-mention lia-mention-user"&gt;Puja&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To accomplish this in DAX, you need to create a calculated table or use measures to dynamically calculate the new row based on the provided logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Solution Using a Calculated Table&lt;/STRONG&gt;&lt;/H3&gt;&lt;LI-CODE lang="markup"&gt;EnhancedTable = 
UNION(
    'OriginalTable', -- Keep all original rows
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER('OriginalTable', 'OriginalTable'[Type] IN {"Wages - Temp Staff", "Payroll Tax Temp"}),
            'OriginalTable'[ID]
        ),
        "Type", "Asset Purchases",
        "Value", 
            (CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Wages - Temp Staff") + 
            CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Payroll Tax Temp")) * -1
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Solution Using a Measure&lt;/STRONG&gt; (If no new rows are required)&lt;/H3&gt;&lt;P&gt;If you want to dynamically calculate the value for "Asset Purchases" in visuals (like a table), use a measure:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Asset Purchases = 
VAR TempStaffValue = 
    CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Wages - Temp Staff")
VAR PayrollTaxValue = 
    CALCULATE(SUM('OriginalTable'[Value]), 'OriginalTable'[Type] = "Payroll Tax Temp")
RETURN
(TempStaffValue + PayrollTaxValue) * -1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Did I answer your question? Mark my post as a solution, this will help others!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If my response(s) assisted you in any way, don't forget to drop me a "&lt;STRONG&gt;Kudos&lt;/STRONG&gt;" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Poojara&lt;BR /&gt;Data Analyst | MSBI Developer | Power BI Consultant&lt;BR /&gt;&lt;STRONG&gt;Please Subscribe my YouTube for Beginners/Advance Concepts:&lt;/STRONG&gt;&amp;nbsp;&lt;A href="https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS" target="_self"&gt;https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 04:46:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4299045#M170717</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2024-11-25T04:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add custom Row based on Dax logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4306967#M171023</link>
      <description>&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Thanks for the reply from Poojara_D12&amp;nbsp; and DataNinja777,&amp;nbsp;please allow me to provide another insight:&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="405743" data-lia-user-login="Puja" class="lia-mention lia-mention-user"&gt;Puja&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Could you please let me know if the responses from Poojara_D12&amp;nbsp; and DataNinja777 have resolved your issue?&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;If it did, kindly accept it as the solution.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;Below is my M language solution to your problem:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    // Load your transaction data
    Source = Table.FromRows(
        {
            {"ID001", "Wages - Temp Staff", 1000},
            {"ID001", "Payroll Tax Temp", 200},
            {"ID002", "Wages - Temp Staff", 1500},
            {"ID002", "Payroll Tax Temp", 300}
        },
        {"ID", "Type", "Value"}
    ),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Type", type text}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Value", each List.Sum([Value])*-1, type nullable number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Type", each "Asset Purchases"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Type", type text}}),
    #"Appended Query" = Table.Combine({#"Changed Type1", #"Changed Type"}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"ID", Order.Ascending}})
in
    #"Sorted Rows"
&lt;/LI-CODE&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;Here is my sample data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;The final result is as follows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;Of course, Poojara_D12&amp;nbsp;'s UNION() function is also a good solution. To facilitate your understanding, I have also created the following example&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;" lang="zh-CN"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Here's my final result, which I hope meets your requirements.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;For further details, please refer to:&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/union-function-dax" target="_blank"&gt;&lt;SPAN&gt;UNION function (DAX) - DAX | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/summarize-function-dax" target="_blank"&gt;&lt;SPAN&gt;SUMMARIZE function (DAX) - DAX | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Please find the attached pbix relevant to the case.&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Leroy Lu&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;If this post &lt;EM&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/EM&gt;, then please consider Accept it &lt;EM&gt;&lt;STRONG&gt;as the solution &lt;/STRONG&gt;&lt;/EM&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2024 05:53:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-custom-Row-based-on-Dax-logic/m-p/4306967#M171023</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-29T05:53:18Z</dc:date>
    </item>
  </channel>
</rss>

