Forum Discussion
Martin_Songstad
3 years agoFrequent Visitor
Merge rows based on continuity
Hi!
How can I calculate a new table like this?
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.
5 Replies
- barritownSolution Sage
Hi Martin_Songstad,
I can propose such a query:
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] ) )If you have no more than 2 adjacent intervals, it should work.
Best Regards,
Alexander
- Martin_SongstadFrequent Visitor
Thanks barritown !
I am not getting excactly the result that I was looking for, but I will look into that code.
- barritownSolution Sage
My solution will break if you try to merge three lines into one, like here:
Age Min Max 19 6575 7000 20 7000 7670 21 7670 8766 If your problem is of a different nature, you can try generating more toy data - maybe I'll come up with some other idea.
Best Regards,
Alexander