<?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: Find % difference between two columns in matrix table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933362#M153029</link>
    <description>&lt;P&gt;1. Make sure your format is Date for the column "Month"&lt;/P&gt;&lt;P&gt;2. Add a new column MonthNb&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUByIjAyMTJR0lQwMDpVgdiKARTNASIWYMV2gEFIwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type date}, {"Value", Int64.Type}}),
    #"Inserted Month" = Table.AddColumn(#"Changed Type", "MonthNb", each Date.Month([Month]), Int64.Type)
in
    #"Inserted Month"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Close Power Query and change the format of the column Month&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Add the DAX measures:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Diff MoM = 
VAR _CurrentValue = SUM(YourTableName[Value])
VAR _vTable = 
OFFSET(
    -1,
    ALL(
        YourTableName[Month],
        YourTableName[Value],
        YourTableName[MonthNb]
    ),
    ORDERBY(YourTableName[Month], ASC),
)

VAR _Selection = 
SELECTCOLUMNS( _vTable, YourTableName[Value])

VAR _PreviousValue = SUMX(_Selection, YourTableName[Value])
VAR _Difference = IF(_PreviousValue &amp;lt;&amp;gt; BLANK() ,_PreviousValue-_CurrentValue)

RETURN 
_Difference

============================
%Diff MoM = 
VAR _CurrentValue = SUM(YourTableName[Value])
VAR _vTable = 
OFFSET(
    -1,
    ALL(
        YourTableName[Month],
        YourTableName[Value],
        YourTableName[MonthNb]
    ),
    ORDERBY(YourTableName[Month], ASC),
)

VAR _Selection = 
SELECTCOLUMNS( _vTable, YourTableName[Value])

VAR _PreviousValue = SUMX(_Selection, YourTableName[Value])
VAR _Difference = IF(_PreviousValue &amp;lt;&amp;gt; BLANK() ,_PreviousValue-_CurrentValue)

RETURN 
DIVIDE(_Difference, _PreviousValue)


==================
SumValue = SUM('YourTableName'[Value])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Use a Matrix column with the column Month on Columns and SumValues, Diff MoM and %Diff MoM&lt;/P&gt;&lt;P&gt;In the format pane choose Values/ Options/ Switch values to rows ON&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;If it answers your query, please mark my reply as the solution. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2024 19:26:24 GMT</pubDate>
    <dc:creator>Alex87</dc:creator>
    <dc:date>2024-05-20T19:26:24Z</dc:date>
    <item>
      <title>Find % difference between two columns in matrix table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933029#M153022</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below Matrix table shows Month headers (text format) and some values for each.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wanting to create two row calcs to show the difference between two months and the % difference:-&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;In Tableau, I used a LOOKUP/OFFSET function to achieve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried using many functions like PARALLELPERIOD or PREVIOUSMONTH, but they all error as the columns are not DATE driven, but TEXT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 16:05:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933029#M153022</guid>
      <dc:creator>Power_It_Up</dc:creator>
      <dc:date>2024-05-20T16:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Find % difference between two columns in matrix table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933083#M153024</link>
      <description>&lt;P&gt;is there any reason you don't want to use DATE format?&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 16:38:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933083#M153024</guid>
      <dc:creator>Alex87</dc:creator>
      <dc:date>2024-05-20T16:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find % difference between two columns in matrix table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933090#M153025</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="729148" data-lia-user-login="Alex87" class="lia-mention lia-mention-user"&gt;Alex87&lt;/a&gt;&amp;nbsp;Hi.&amp;nbsp; Not really.&amp;nbsp; I used the FORMAT option to change the full date to just months, which made them into TEXT.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 16:41:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933090#M153025</guid>
      <dc:creator>Power_It_Up</dc:creator>
      <dc:date>2024-05-20T16:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find % difference between two columns in matrix table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933362#M153029</link>
      <description>&lt;P&gt;1. Make sure your format is Date for the column "Month"&lt;/P&gt;&lt;P&gt;2. Add a new column MonthNb&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUByIjAyMTJR0lQwMDpVgdiKARTNASIWYMV2gEFIwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type date}, {"Value", Int64.Type}}),
    #"Inserted Month" = Table.AddColumn(#"Changed Type", "MonthNb", each Date.Month([Month]), Int64.Type)
in
    #"Inserted Month"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Close Power Query and change the format of the column Month&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Add the DAX measures:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Diff MoM = 
VAR _CurrentValue = SUM(YourTableName[Value])
VAR _vTable = 
OFFSET(
    -1,
    ALL(
        YourTableName[Month],
        YourTableName[Value],
        YourTableName[MonthNb]
    ),
    ORDERBY(YourTableName[Month], ASC),
)

VAR _Selection = 
SELECTCOLUMNS( _vTable, YourTableName[Value])

VAR _PreviousValue = SUMX(_Selection, YourTableName[Value])
VAR _Difference = IF(_PreviousValue &amp;lt;&amp;gt; BLANK() ,_PreviousValue-_CurrentValue)

RETURN 
_Difference

============================
%Diff MoM = 
VAR _CurrentValue = SUM(YourTableName[Value])
VAR _vTable = 
OFFSET(
    -1,
    ALL(
        YourTableName[Month],
        YourTableName[Value],
        YourTableName[MonthNb]
    ),
    ORDERBY(YourTableName[Month], ASC),
)

VAR _Selection = 
SELECTCOLUMNS( _vTable, YourTableName[Value])

VAR _PreviousValue = SUMX(_Selection, YourTableName[Value])
VAR _Difference = IF(_PreviousValue &amp;lt;&amp;gt; BLANK() ,_PreviousValue-_CurrentValue)

RETURN 
DIVIDE(_Difference, _PreviousValue)


==================
SumValue = SUM('YourTableName'[Value])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Use a Matrix column with the column Month on Columns and SumValues, Diff MoM and %Diff MoM&lt;/P&gt;&lt;P&gt;In the format pane choose Values/ Options/ Switch values to rows ON&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;If it answers your query, please mark my reply as the solution. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 19:26:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3933362#M153029</guid>
      <dc:creator>Alex87</dc:creator>
      <dc:date>2024-05-20T19:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find % difference between two columns in matrix table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3963648#M153761</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="729148" data-lia-user-login="Alex87" class="lia-mention lia-mention-user"&gt;Alex87&lt;/a&gt;. Firstly, my apologies for not replying to you sooner.&amp;nbsp; Many thanks for your input on this.&amp;nbsp; Apart from the percentages being slightly out (should be -10% and +33%, which I amended), this worked well and it was insightful how you used the OFFSET function.&amp;nbsp; Thanks again. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 08:34:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Find-difference-between-two-columns-in-matrix-table/m-p/3963648#M153761</guid>
      <dc:creator>Power_It_Up</dc:creator>
      <dc:date>2024-05-31T08:34:28Z</dc:date>
    </item>
  </channel>
</rss>

