Wednesday, July 1, 2020

How to concatenating multiple rows of record into One record row in Cognos queries

The link below from IBM demonstrated a solution to resolve this issue. However, it could be very slow duo to master detail relationship. in addition, it is not flexible at all. This article shows you another practical way to resolve this issue at Query level.

https://www.ibm.com/support/pages/how-combine-rows-list-report-single-row-comma-separated  How to combine rows in a list report into a single row that is comma separated.


Report output
Basic Data
Column1Column2Measure1Rank4Column2DistinctCount4Column2Column21Column22Column23Column24Column25
CTL 309306IS-5109771022IS-510977
CTL 309316IS-5109791022IS-510979
CTL 309316IS-5109801012IS-510980
CTL 309306IS-5111291012IS-511129
Report DataColumn1ConcatenationOfColumn2Measure1
CTL 309306IS-511129;IS-51097720
CTL 309316IS-510980;IS-51097920
Report columns
Rank4Column2rank  ( [Column2] for [Column1])
DistinctCount4Column2count( distinct [Column2] for [Column1])
Column21if ([Rank4Column2] = 1) THEN ([Column2]) ELSE (null)
Column22if ([Rank4Column2] = 2) THEN ([Column2]) ELSE (null)
Column23if ([Rank4Column2] = 3) THEN ([Column2]) ELSE (null)
Column24if ([Rank4Column2] = 4) THEN ([Column2]) ELSE (null)
Column25if ([Rank4Column2] = 5) THEN ([Column2]) ELSE (null)
ConcatenationOfColumn2 - CALCULATEDCASE WHEN maximum([BasicData].[DistinctCount4Column2]) = 1 THEN maximum([BasicData].[Column21])
WHEN maximum([BasicData].[DistinctCount4Column2]) = 2 THEN maximum([BasicData].[Column21]) || ';' || maximum([BasicData].[Column22])
WHEN maximum([BasicData].[DistinctCount4Column2]) = 3 THEN maximum([BasicData].[Column21]) || ';' || maximum([BasicData].[Column22]) || ';' || maximum([BasicData].[Column23])
WHEN maximum([BasicData].[DistinctCount4Column2]) = 4 THEN maximum([BasicData].[Column21]) || ';' || maximum([BasicData].[Column22]) || ';' || maximum([BasicData].[Column23]) || ';' || maximum([BasicData].[Column24])
WHEN maximum([BasicData].[DistinctCount4Column2]) = 5 THEN maximum([BasicData].[Column21]) || ';' || maximum([BasicData].[Column22]) || ';' || maximum([BasicData].[Column23]) || ';' || maximum([BasicData].[Column24]) || ';' || maximum([BasicData].[Column25])
END

No comments:

Post a Comment