<?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: Merge rows based on continuity in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3203272#M116549</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="404227" data-lia-user-login="Martin_Songstad" class="lia-mention lia-mention-user"&gt;Martin_Songstad&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can propose such a query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Result Table = 
VAR _temp = ADDCOLUMNS ( data,
                         "NewMin", COALESCE ( LOOKUPVALUE ( data[Min], data[Max], data[Min] ), data[Min] ),
                         "NewMax", COALESCE ( LOOKUPVALUE ( data[Max], data[Min], data[Max] ), data[Max] ) )
RETURN DISTINCT ( SELECTCOLUMNS (_temp, "Min", [NewMin], "Max", [NewMax] ) )&lt;/LI-CODE&gt;&lt;P&gt;If you have no more than 2 adjacent intervals, it should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Best Regards, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Alexander&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@powerbi-vlog" target="_blank"&gt;My YouTube vlog in English&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@pbi-vlog" target="_blank"&gt;My YouTube vlog in Russian&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 15:28:02 GMT</pubDate>
    <dc:creator>barritown</dc:creator>
    <dc:date>2023-04-24T15:28:02Z</dc:date>
    <item>
      <title>Merge rows based on continuity</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3202415#M116458</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I calculate a new table like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Ages 19 and 20 are adjacent to each other in this filter context, so I want to lump them together in the background to reduce the number of iterations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 08:35:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3202415#M116458</guid>
      <dc:creator>Martin_Songstad</dc:creator>
      <dc:date>2023-04-24T08:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merge rows based on continuity</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3203272#M116549</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="404227" data-lia-user-login="Martin_Songstad" class="lia-mention lia-mention-user"&gt;Martin_Songstad&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can propose such a query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Result Table = 
VAR _temp = ADDCOLUMNS ( data,
                         "NewMin", COALESCE ( LOOKUPVALUE ( data[Min], data[Max], data[Min] ), data[Min] ),
                         "NewMax", COALESCE ( LOOKUPVALUE ( data[Max], data[Min], data[Max] ), data[Max] ) )
RETURN DISTINCT ( SELECTCOLUMNS (_temp, "Min", [NewMin], "Max", [NewMax] ) )&lt;/LI-CODE&gt;&lt;P&gt;If you have no more than 2 adjacent intervals, it should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Best Regards, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Alexander&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@powerbi-vlog" target="_blank"&gt;My YouTube vlog in English&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@pbi-vlog" target="_blank"&gt;My YouTube vlog in Russian&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 15:28:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3203272#M116549</guid>
      <dc:creator>barritown</dc:creator>
      <dc:date>2023-04-24T15:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge rows based on continuity</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3204436#M116654</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="518952" data-lia-user-login="barritown" class="lia-mention lia-mention-user"&gt;barritown&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not getting excactly the result that I was looking for, but I will look into that code.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 07:24:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3204436#M116654</guid>
      <dc:creator>Martin_Songstad</dc:creator>
      <dc:date>2023-04-25T07:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merge rows based on continuity</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3204487#M116658</link>
      <description>&lt;P&gt;My solution will break if you try to merge three lines into one, like here:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Age&lt;/TD&gt;&lt;TD&gt;Min&lt;/TD&gt;&lt;TD&gt;Max&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;6575&lt;/TD&gt;&lt;TD&gt;7000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;7000&lt;/TD&gt;&lt;TD&gt;7670&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;7670&lt;/TD&gt;&lt;TD&gt;8766&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your problem is of a different nature, you can try generating more toy data - maybe I'll come up with some other idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Best Regards, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Alexander&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@powerbi-vlog" target="_blank" rel="noopener"&gt;My YouTube vlog in English&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@pbi-vlog" target="_blank" rel="noopener"&gt;My YouTube vlog in Russian&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 07:50:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3204487#M116658</guid>
      <dc:creator>barritown</dc:creator>
      <dc:date>2023-04-25T07:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Merge rows based on continuity</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3204509#M116659</link>
      <description>&lt;P&gt;Yes i would like to merge all continuously selected age groups.&lt;/P&gt;&lt;P&gt;This is the best take I have come up with myself so far:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EVALUATE

VAR __Simulated_selection =

FILTER(
	ALL(Aldersgrupper[Alder]),
	Aldersgrupper[Alder] = 19 || Aldersgrupper[Alder] = 20 || Aldersgrupper[Alder] = 22
	)

VAR __MinValues =
CALCULATETABLE(
CALCULATETABLE(
	SELECTCOLUMNS(Aldersgrupper,
					"Min", Aldersgrupper[Min],
					"Rank", RANKX(Aldersgrupper, [Min],,1)
					),
	EXCEPT( VALUES( Aldersgrupper[Min] ), 
			SELECTCOLUMNS(Aldersgrupper,
							"Max", Aldersgrupper[Max]) )
),
__Simulated_selection)

VAR __MaxValues =
CALCULATETABLE(
CALCULATETABLE(
	SELECTCOLUMNS(Aldersgrupper,
					"Max", Aldersgrupper[Max],
					"Rank", RANKX(Aldersgrupper, [Max],,1)
					),
	EXCEPT( VALUES( Aldersgrupper[Max] ), 
			SELECTCOLUMNS(Aldersgrupper,
							"Min", Aldersgrupper[Min]) )
),
__Simulated_selection)

VAR __AgeGroupsCompressed =
NATURALINNERJOIN(__MinValues,__MaxValues )

RETURN __AgeGroupsCompressed&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 25 Apr 2023 07:56:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3204509#M116659</guid>
      <dc:creator>Martin_Songstad</dc:creator>
      <dc:date>2023-04-25T07:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merge rows based on continuity</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3205373#M116731</link>
      <description>&lt;P&gt;I have an idea, which works on the test dataset below, but with my current [DAX] knowledge I am unable to pack it up into one single query.&amp;nbsp;Take a look, maybe you will be able to achieve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test dataset:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We put all the minimums and maximums into one table, mark (1 - max, 0 - min in Status) and rank them.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 2 (this is the main obstacle why I cannot pack it up into a single query).&lt;/P&gt;&lt;P&gt;We add a calculated column which flags the first minimum and last maximum in each sequence.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 3.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We produce an output by filtering, re-ranking and joining tables.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For convenience, here are those tables and column in the text format:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;one_column_view = 
VAR _tmp = UNION (
ADDCOLUMNS ( SELECTCOLUMNS ( data, "Value", data[Min] ), "Status", {0} ), 
ADDCOLUMNS ( SELECTCOLUMNS ( data, "Value", data[Max] ), "Status", {1} ) )
VAR _tmp2 = ADDCOLUMNS ( _tmp, "id", RANKX ( _tmp, [Value], , 1, Dense ) )
RETURN _tmp2&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;flag = 
VAR cur_id = [id]
VAR part1 = IF ( one_column_view[Status] = 0 &amp;amp;&amp;amp; one_column_view[Status] &amp;lt;&amp;gt; CALCULATE ( MAX ( one_column_view[Status] ) , ALL ( one_column_view ), one_column_view[id] = cur_id - 1 ) || [id] = 1, 1, 0 )
VAR part2 = IF ( one_column_view[Status] = 1 &amp;amp;&amp;amp; one_column_view[Status] &amp;lt;&amp;gt; CALCULATE ( MAX ( one_column_view[Status] ) , ALL ( one_column_view ), one_column_view[id] = cur_id + 1 ), 1, 0 )
RETURN part1 + part2&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;result = 
VAR _tmp = CALCULATETABLE ( one_column_view, one_column_view[flag] = 1 )
VAR _tmp2 = SELECTCOLUMNS ( _tmp, "Value", [Value], "Rank", RANKX ( _tmp, [Value], , ASC ), "Status", [Status] )
VAR _mins = SELECTCOLUMNS ( FILTER ( _tmp2, [Status] = 0 ), "Min", [Value], "Rank", INT ( [Rank] / 2 ) + 1 )
VAR _maxs = SELECTCOLUMNS ( FILTER ( _tmp2, [Status] = 1 ), "Max", [Value], "Rank", INT ( [Rank] / 2 ) )
RETURN NATURALINNERJOIN ( _mins, _maxs )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Best Regards, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Alexander&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@powerbi-vlog" target="_blank"&gt;My YouTube vlog in English&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@pbi-vlog" target="_blank"&gt;My YouTube vlog in Russian&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 15:12:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Merge-rows-based-on-continuity/m-p/3205373#M116731</guid>
      <dc:creator>barritown</dc:creator>
      <dc:date>2023-04-25T15:12:43Z</dc:date>
    </item>
  </channel>
</rss>

