<?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 What is the purpose of this code block RETURN below? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-purpose-of-this-code-block-RETURN-below/m-p/3674995#M142641</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;Today I was handled by my colleague her report! Unfortunately she was not here to explain some code for me and there is no documentation so I need some help to show me what does the code in RETURN block do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;@Table = 
VAR _toPathsTable =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            '_G Vendors',
            "VendorID", '_G Vendors'[USERNAME],
            "@RFNo", SUBSTITUTE ( '_G Vendors'[POSITION], ",", "|" )
        ),
        "@Length", PATHLENGTH ( [@RFNo] )
    )
VAR T =
    ADDCOLUMNS (
        _toPathsTable,
        "@Cumulative", SUMX ( FILTER ( _toPathsTable, [VendorID] &amp;lt;= EARLIER ( [VendorID] ) ), [@Length] )
    )
RETURN
    ADDCOLUMNS (
        SELECTCOLUMNS (
            ADDCOLUMNS (
                GENERATESERIES ( 1, SUMX ( T, [@Length] ) ),
                "Cumulative", MINX ( FILTER ( T, [@Cumulative] &amp;gt;= [Value] ), [@Cumulative] )
            ),
            "VendorID", MAXX ( FILTER ( T, [@Cumulative] = [Cumulative] ), [VendorID] ),
            "RF Combined", MAXX ( FILTER ( T, [@Cumulative] = [Cumulative] ), [@RFNo] ),
            "RF Count", 1 + [Cumulative] - [Value]
        ),
        "RFNo", TRIM(PATHITEM( [RF Combined], [RF Count] ))
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Here are some snippet data for each temporary table:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_toPathsTable returned data:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The T table is added Cumulative column base on VendorID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the RETURN block I have no idea why she use GENERATESERIES function also the "RF Combined" and "RF Count" are disapeared from the returned data:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for any help&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2024 08:16:10 GMT</pubDate>
    <dc:creator>TungNguyen_19</dc:creator>
    <dc:date>2024-02-02T08:16:10Z</dc:date>
    <item>
      <title>What is the purpose of this code block RETURN below?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-purpose-of-this-code-block-RETURN-below/m-p/3674995#M142641</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;Today I was handled by my colleague her report! Unfortunately she was not here to explain some code for me and there is no documentation so I need some help to show me what does the code in RETURN block do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;@Table = 
VAR _toPathsTable =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            '_G Vendors',
            "VendorID", '_G Vendors'[USERNAME],
            "@RFNo", SUBSTITUTE ( '_G Vendors'[POSITION], ",", "|" )
        ),
        "@Length", PATHLENGTH ( [@RFNo] )
    )
VAR T =
    ADDCOLUMNS (
        _toPathsTable,
        "@Cumulative", SUMX ( FILTER ( _toPathsTable, [VendorID] &amp;lt;= EARLIER ( [VendorID] ) ), [@Length] )
    )
RETURN
    ADDCOLUMNS (
        SELECTCOLUMNS (
            ADDCOLUMNS (
                GENERATESERIES ( 1, SUMX ( T, [@Length] ) ),
                "Cumulative", MINX ( FILTER ( T, [@Cumulative] &amp;gt;= [Value] ), [@Cumulative] )
            ),
            "VendorID", MAXX ( FILTER ( T, [@Cumulative] = [Cumulative] ), [VendorID] ),
            "RF Combined", MAXX ( FILTER ( T, [@Cumulative] = [Cumulative] ), [@RFNo] ),
            "RF Count", 1 + [Cumulative] - [Value]
        ),
        "RFNo", TRIM(PATHITEM( [RF Combined], [RF Count] ))
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Here are some snippet data for each temporary table:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_toPathsTable returned data:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The T table is added Cumulative column base on VendorID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the RETURN block I have no idea why she use GENERATESERIES function also the "RF Combined" and "RF Count" are disapeared from the returned data:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for any help&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 08:16:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-purpose-of-this-code-block-RETURN-below/m-p/3674995#M142641</guid>
      <dc:creator>TungNguyen_19</dc:creator>
      <dc:date>2024-02-02T08:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of this code block RETURN below?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-purpose-of-this-code-block-RETURN-below/m-p/3675246#M142656</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;The purpose of the RETURN block in the provided DAX (Data Analysis Expressions) code is to generate a new table as the output of the entire DAX query. Let's break down the RETURN block and its purpose:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;GENERATESERIES Function&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The GENERATESERIES function generates a table with a single column containing sequential numbers.&lt;/LI&gt;&lt;LI&gt;In this context, it seems to be used to generate a series of numbers from 1 to the total length of the cumulative path lengths calculated earlier in the query.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Transformation and Filtering&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The MINX function inside the GENERATESERIES column computes the cumulative path lengths until the current row, and the MINX function retrieves the minimum cumulative path length that is greater than or equal to the current row's value.&lt;/LI&gt;&lt;LI&gt;This part seems to be constructing a new table where each row represents a specific point in the cumulative path lengths.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;SELECTCOLUMNS and ADDCOLUMNS&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The SELECTCOLUMNS function is used to select specific columns from an existing table or transform columns.&lt;/LI&gt;&lt;LI&gt;The ADDCOLUMNS function is used to add new calculated columns to a table.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Transformation of RF Combined and RF Count&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The "RF Combined" and "RF Count" columns are indeed present in the final output, but they are being transformed in a way that the "RF Combined" values are filtered based on the cumulative counts, and "RF Count" seems to be recalculated.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Final Output&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The final output of the RETURN block is a new table that comprises columns such as "VendorID", "RF Combined", and "RF Count" based on the calculations and transformations applied within the block.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;In summary, the RETURN block is constructing a new table based on the previously defined tables and calculations. It seems to be transforming the cumulative path lengths and combining them with specific vendor IDs and RF numbers, resulting in a structured output.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&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;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 02 Feb 2024 09:48:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-purpose-of-this-code-block-RETURN-below/m-p/3675246#M142656</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-02-02T09:48:52Z</dc:date>
    </item>
  </channel>
</rss>

