Forum Discussion
Anonymous
6 years agoNot applicable
Compress rows in a table
Hi In Excel, I have a vba macro which basically compresses rowsin a table which have same values Logic is ELR, TID, CODE should match and FM = SM of next row In Excel, I update the FM with the...
v-zhenbw-msft
6 years agoCommunity Support
Hi Anonymous ,
We can use the following steps to meet your requirement.
1. Create a calculated column.
IsEqualToNextRow =
[Finish Mileage]
= CALCULATE (
SUM ( 'INM'[Start Mileage] ),
'INM',
'INM'[INDEX]
= EARLIER ( 'INM'[INDEX] ) + 1,
'INM'[ELR] = EARLIER ( 'INM'[ELR] ),
INM[CODE] = EARLIER ( 'INM'[CODE] ),
'INM'[Track ID] = EARLIER ( 'INM'[Track ID] )
)
2. Then we can create a calculate column to get the result.
Group =
VAR temp =
CALCULATE (
MAX ( 'INM'[INDEX] ),
'INM',
NOT ( 'INM'[IsEqualToNextRow] ),
'INM'[INDEX] < EARLIER ( 'INM'[INDEX] ),
'INM'[ELR] = EARLIER ( 'INM'[ELR] ),
INM[CODE] = EARLIER ( 'INM'[CODE] ),
'INM'[Track ID] = EARLIER ( 'INM'[Track ID] )
)
RETURN
IF (
CALCULATE (
COUNTROWS ( 'INM' ),
'INM'[IsEqualToNextRow],
'INM',
'INM'[INDEX]
= EARLIER ( 'INM'[INDEX] ) - 1,
'INM'[ELR] = EARLIER ( 'INM'[ELR] ),
INM[CODE] = EARLIER ( 'INM'[CODE] ),
'INM'[Track ID] = EARLIER ( 'INM'[Track ID] )
) > 0,
CALCULATE (
MIN ( 'INM'[INDEX] ),
'INM',
'INM'[INDEX] < EARLIER ( 'INM'[INDEX] ),
'INM'[INDEX] > temp,
'INM'[ELR] = EARLIER ( 'INM'[ELR] ),
INM[CODE] = EARLIER ( 'INM'[CODE] ),
'INM'[Track ID] = EARLIER ( 'INM'[Track ID] )
),
[INDEX]
)
BTW, pbix as attached.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
6 years agoNot applicable
Many thanks. Your solution worked perfectly. When grouped, it gave same result as my vba macro ... which I now dont need to run every time the data refreshes