<?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 Calculation group showing change linked by version number in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3670971#M142409</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My tables have SCD type 2 with a version ID that links versions of the same record:&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;My goal is to create a calculation group that returns for each measure in a table the difference between the (current) version and the previous version (like columns 'PriceChange' and 'QuantityChange' in the example above).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this is some form of row level calculation but I am stuck at how to calculate this. If necessary I would be able to add a column with a reference to the (unique) ID of the corresponding previous version row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to stay away from calculated columns because some tables have hundreds of measures. A calculation group would allow me to apply the same logic to all measures and all tables within the data model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all the help.&lt;/P&gt;&lt;P&gt;Martijn&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2024 20:55:04 GMT</pubDate>
    <dc:creator>Blaenzo</dc:creator>
    <dc:date>2024-01-31T20:55:04Z</dc:date>
    <item>
      <title>Calculation group showing change linked by version number</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3670971#M142409</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My tables have SCD type 2 with a version ID that links versions of the same record:&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;My goal is to create a calculation group that returns for each measure in a table the difference between the (current) version and the previous version (like columns 'PriceChange' and 'QuantityChange' in the example above).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this is some form of row level calculation but I am stuck at how to calculate this. If necessary I would be able to add a column with a reference to the (unique) ID of the corresponding previous version row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to stay away from calculated columns because some tables have hundreds of measures. A calculation group would allow me to apply the same logic to all measures and all tables within the data model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all the help.&lt;/P&gt;&lt;P&gt;Martijn&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 20:55:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3670971#M142409</guid>
      <dc:creator>Blaenzo</dc:creator>
      <dc:date>2024-01-31T20:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation group showing change linked by version number</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3672714#M142488</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="97423" data-lia-user-login="Blaenzo" class="lia-mention lia-mention-user"&gt;Blaenzo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Measures:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PriceMeasure =

CALCULATE ( SUMX ( 'Table', 'Table'[Price] ) )



QuantityMeasure =

CALCULATE ( SUMX ( 'Table', 'Table'[Quantity] ) )



VersionDiff =

VAR _prod_id =

    SELECTEDVALUE ( 'Table'[ProductID] )

VAR _id =

    SELECTEDVALUE ( 'Table'[ID] )

VAR _ver =

    SELECTEDVALUE ( 'Table'[Version] )

VAR _pre_ver =

    CALCULATE (

        MAX ( 'Table'[Version] ),

        FILTER (

            ALL ( 'Table' ),

            'Table'[Version] = _ver - 1

                &amp;amp;&amp;amp; 'Table'[ProductID] = _prod_id

        )

    )

VAR _diff_ver =

    IF ( NOT ISBLANK ( _pre_ver ), _ver - _pre_ver )

RETURN

    _diff_ver





PriceDiff =

VAR _ID =

    MAXX ( FILTER ( ALL ( 'Table' ), [ID] &amp;lt; SELECTEDVALUE ( 'Table'[ID] ) ), [ID] )

VAR _previousDiff =

    CALCULATE (

        SUM ( 'Table'[Price] ),

        FILTER ( ALL ( 'Table' ), 'Table'[ID] = _ID )

    )

VAR _diff =

    CALCULATE ( 'Table'[PriceMeasure] - _previousDiff )

RETURN

    IF ( [VersionDiff] = 1, _diff )





QuantityDiff =

VAR _ID =

    MAXX ( FILTER ( ALL ( 'Table' ), [ID] &amp;lt; SELECTEDVALUE ( 'Table'[ID] ) ), [ID] )

VAR _previousDiff =

    CALCULATE (

        SUM ( 'Table'[Quantity] ),

        FILTER ( ALL ( 'Table' ), 'Table'[ID] = _ID )

    )

VAR _diff =

    CALCULATE ( 'Table'[QuantityMeasure] - _previousDiff )

RETURN

    IF ( [VersionDiff] = 1, _diff )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this does not work, could you please share some sample data without sensitive information and expected output.&lt;BR /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;How to provide sample data in the Power BI Forum - Microsoft Fabric Community&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;to&lt;/STRONG&gt; help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank"&gt;How to get your questions answered quickly&lt;/A&gt;&amp;nbsp;--&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;&amp;nbsp;How to provide sample data in the Power BI Forum&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 10:33:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3672714#M142488</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-01T10:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation group showing change linked by version number</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3697282#M143777</link>
      <description>&lt;P&gt;Hi Yang, thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have succesfully tested your approach. However, 'SELECTEDVALUE()' only works if the row context contains only one row for the relevant fields. This approach no longer works at an aggregate level, e.g. in a matrix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I decided to use the OFFSET function as described here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/best-practices/dax-understand-orderby" target="_blank"&gt;Understanding ORDERBY, PARTITIONBY, and MATCHBY functions in DAX - DAX | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, for the following table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;the measure&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;PrevVal = CALCULATE(SUM(TestTable1[Val]),OFFSET(-1,,ORDERBY(TestTable1[VERSION], ASC),,PARTITIONBY(TestTable1[LeaseID])))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gives&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;and aggregated by version:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am using SSAS Tabular 1600 (version&amp;nbsp;16.0.43.222) and the implemenation of OFFSET in SSAS appears to be riddled with bugs and incomplete vs PowerBI (e.g. MATCHBY() is not supported).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bugs that I ran into:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;both PARTITIONBY() and ORDERBY() won't work with integers (like in my case LeaseID and VERSION).&lt;BR /&gt;Changing those fields to STRING in the datamodel (not in the actual sql table) resolved this issue.&lt;/LI&gt;&lt;LI&gt;A table and matrix visual will crash if (sub-)totals are enabled, while this works fine using PowerBI directly linked to the same DB table (i.e. without an SSAS data model).&lt;/LI&gt;&lt;LI&gt;Trying to work around this using IFERROR() and ISERROR() does not work and the measure will return an error (i.e. the visual crashes) regardsless. IFERROR() not catching errors happened in the past for certain functions until that was fixed if I remember correctly.&lt;/LI&gt;&lt;LI&gt;Probably related to 2) above; aggregation in a matrix does not work&lt;/LI&gt;&lt;LI&gt;Evaluating a DAX statement in SSMS with an explicit measure containing OFFSET fails, while the exact same measure created in SSAS runs fine in that exact same DAX query. This should be equivalent.&lt;/LI&gt;&lt;LI&gt;Using OFFSET in a calculation group works to some extent but has a significant flaw, possibly related to 3) above:&lt;BR /&gt;Assume two calculaton items 'Current' and 'Prev':&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Current=SELECTEDMEASURE()

Prev=
    IF(
        ISSELECTEDMEASURE([Sum of Val]),
        CALCULATE(SELECTEDMEASURE()),OFFSET(-1,,ORDERBY(TestTable1[VERSION], ASC),,PARTITIONBY(TestTable1[LeaseID]))),
        SELECTEDMEASURE()
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Then, if only 'Current' is selected, &lt;U&gt;'Prev' is evaluated regardless&lt;/U&gt; and results in the visual crashing if the OFFSET calculation is not applicable in a given filter context. This is very strange.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Also, when another measure is included (e.g. [Sum of Val2]), for calculation item 'Prev' (or 'Current'), the IF statement should simply return 'SELECTEDMEASURE()' and skip the evaluation of the OFFSET formula. However, the IF statement does evaluate it leading to an error, which conflicts with the implementation of the IF statement. This makes the current usablilty if the OFFSET function in a calculation group very limited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All these situations typically result in the following error even when there is one match:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;PartitionBy column 'LeaseID' does not match any row context or filter context. OrderBy and PartitionBy columns must have exactly one match.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be the best way to raise these bugs with Microsoft?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 21:15:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-group-showing-change-linked-by-version-number/m-p/3697282#M143777</guid>
      <dc:creator>Blaenzo</dc:creator>
      <dc:date>2024-02-13T21:15:08Z</dc:date>
    </item>
  </channel>
</rss>

