<?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: Create a new table from another and add new calculations from rows to columns in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856119#M91809</link>
    <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;You could do this in PQ:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcg41VNJRAmMDA6VYHZiIEQjDRYygasxQREDYBC5iDFVjChKJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customers = _t, Labels = _t, Inputs = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customers", type text}, {"Labels", Int64.Type}, {"Inputs", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Labels", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Labels", type text}}, "en-US")[Labels]), "Labels", "Inputs", List.Sum),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1", "Label1"}, {"2", "Label2"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",null,0,Replacer.ReplaceValue,{"Label2"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "Output", each [Label1] - [Label2])
in
    #"Added Custom"&lt;/LI-CODE&gt;
&lt;P&gt;and here is a DAX solution as well:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table3 = 
    ADDCOLUMNS(
        ADDCOLUMNS(
            DISTINCT('Table'[Customers]),
            "Label1", SUMX(FILTER('Table',[Labels] = 1 &amp;amp;&amp;amp; [Customers] = EARLIER([Customers])),[Inputs]),
            "Label2", SUMX(FILTER('Table',[Labels] = 2 &amp;amp;&amp;amp; [Customers] = EARLIER([Customers])),[Inputs])
        ),
        "Output",[Label1] - [Label2]
    )&lt;/LI-CODE&gt;
&lt;P&gt;PBIX is attached below signature.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Oct 2022 17:28:38 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2022-10-21T17:28:38Z</dc:date>
    <item>
      <title>Create a new table from another and add new calculations from rows to columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856031#M91806</link>
      <description>&lt;P&gt;Hi, I need to create a new set of measures, but they depend of other values in a preexisting source of data. In SQL I managed this by adding CASE sentences to transform a row into a column and then I operated the columns, but in DAX I'm not sure about what is the best option, so I'm guessing that is through a new table with the SWITCH function involved. Let me explain my need:&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;</description>
      <pubDate>Fri, 21 Oct 2022 16:01:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856031#M91806</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-21T16:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new table from another and add new calculations from rows to columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856119#M91809</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;You could do this in PQ:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcg41VNJRAmMDA6VYHZiIEQjDRYygasxQREDYBC5iDFVjChKJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customers = _t, Labels = _t, Inputs = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customers", type text}, {"Labels", Int64.Type}, {"Inputs", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Labels", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Labels", type text}}, "en-US")[Labels]), "Labels", "Inputs", List.Sum),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1", "Label1"}, {"2", "Label2"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",null,0,Replacer.ReplaceValue,{"Label2"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "Output", each [Label1] - [Label2])
in
    #"Added Custom"&lt;/LI-CODE&gt;
&lt;P&gt;and here is a DAX solution as well:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table3 = 
    ADDCOLUMNS(
        ADDCOLUMNS(
            DISTINCT('Table'[Customers]),
            "Label1", SUMX(FILTER('Table',[Labels] = 1 &amp;amp;&amp;amp; [Customers] = EARLIER([Customers])),[Inputs]),
            "Label2", SUMX(FILTER('Table',[Labels] = 2 &amp;amp;&amp;amp; [Customers] = EARLIER([Customers])),[Inputs])
        ),
        "Output",[Label1] - [Label2]
    )&lt;/LI-CODE&gt;
&lt;P&gt;PBIX is attached below signature.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 17:28:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856119#M91809</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2022-10-21T17:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new table from another and add new calculations from rows to columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856222#M91817</link>
      <description>&lt;P&gt;@Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please try&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Desired =
GENERATE (
    VALUES ( Source[Customers] ),
    VAR Label1 =
        CALCULATE ( SUM ( Source[Inputs] ), Source[Labels] = 1 )
    VAR Label2 =
        CALCULATE ( SUM ( Source[Inputs] ), Source[Labels] = 2 )
    VAR Outputs = Label1 - Label2
    RETURN
        ROW ( "Label1", Label1, "Label2", Label2, "Outputs", Outputs )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 21 Oct 2022 19:00:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-a-new-table-from-another-and-add-new-calculations-from/m-p/2856222#M91817</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-10-21T19:00:53Z</dc:date>
    </item>
  </channel>
</rss>

