Forum Discussion
Group different rows into one (same data)
- 4 years ago
Hi Anonymous
I though I've had replied back to you with updated solution but for some reason I caanot see my reply. Heree is the sample file https://www.dropbox.com/t/mrD8taPTCHSWO8P2Please try this solution if it works. However, this is not a perfect situation for a 17M rows data.
Shipments Summary 2 = VAR T1 = SUMMARIZE ( Shipments, Shipments[ShipmentId], Shipments[HUUID], "Waypoint", MAX ( Shipments[Waypoints] ) ) VAR T2 = GENERATE ( T1, VAR T3 = CALCULATETABLE ( Shipments ) VAR T4 = ADDCOLUMNS ( T3, "@Rank", RANKX ( FILTER ( T3, [Waypoints_Actual] <> BLANK ( ) ), [Extraction_date] ) ) VAR FirstReroute = MAXX ( FILTER ( T4, [@Rank] = 2 ), [Waypoints_actual] ) VAR SecondReroute = MAXX ( FILTER ( T4, [@Rank] = 1 ), [Waypoints_actual] ) RETURN ROW ( "1st Route", FirstReroute, "2nd Route", SecondReroute,"3rd Route", FirstReroute ) ) RETURN T2
Hi Anonymous
If you are interested in a DAX solution then I have two options for you:
Option 1: Dynamic number of columns using a measure. This is the solution that I prefer. It is simple and completely dynamic.
You need to have a filter table that contains the Reroute numbers up to the maximum possible. You can just create it in excel and import it. Here is a simple DAX for up to 10 nos
Reroute Order =
SELECTCOLUMNS (
{
( "1st Reroute", 1 ),
( "2nd Reroute", 2 ),
( "3rd Reroute", 3 ),
( "4th Reroute", 4 ),
( "5th Reroute", 5 ),
( "6th Reroute", 6 ),
( "7th Reroute", 7 ),
( "8th Reroute", 8 ),
( "9th Reroute", 9 ),
( "10th Reroute", 10 )
},
"Reroute Order", [Value1], "# Reroute Order", [Value2]
)
This will be just a disconnected table that will be used for slicing the matrix (will be placed on the columns of the matrix)
Then you can create your measure as follows. Place ShipmentId and HUUID in the Rows of the matrix and place the measure in the values. Then place the Reroute Order column from the new table in the columns.
Actual Waypoint =
VAR T1 = FILTER ( Shipments, [Waypoints_Actual] <> BLANK ( ) )
VAR T2 = ADDCOLUMNS ( T1, "@Rank", RANKX ( T1, [Extraction_date] ) )
VAR CurrentRank = SELECTEDVALUE ( 'Reroute Order'[# Reroute Order] )
VAR T3 = FILTER ( T2, [@Rank] = CurrentRank )
RETURN
MAXX ( T3, [Waypoints_actual] )
Option 2: Create a new calculated table as follows
Shipments Summary =
VAR T1 = SUMMARIZE ( Shipments, Shipments[ShipmentId], Shipments[HUUID] )
VAR T2 =
GENERATE (
T1,
VAR T3 = CALCULATETABLE ( Shipments )
VAR T4 =
ADDCOLUMNS (
T3,
"@Length1", LEN ( [Waypoints] ),
"@Lenth2", LEN ( [Waypoints_Actual] ),
"@Rank", RANKX ( FILTER ( T3, [Waypoints_Actual] <> BLANK ( ) ), [Extraction_date] )
)
VAR LongestWaypoint1 = MAXX ( TOPN ( 1, T4, [@Length1] ), [Waypoint] )
VAR LongestWaypoint2 = MAXX ( TOPN ( 1, T4, [@Length1] ), [Waypoint_Actual] )
VAR FirstReroute = MAXX ( FILTER ( T4, [@Rank] = 1 ), [Waypoints_actual] )
VAR SecondReroute = MAXX ( FILTER ( T4, [@Rank] = 2 ), [Waypoints_actual] )
RETURN
ROW ( "Waypoint", LongestWaypoint1, "Waypoint_Actual", LongestWaypoint2, "1st Route", FirstReroute, "2nd Route", SecondReroute )
)
RETURN
T2
This solution is not dynamic you you need to hard-code the number of columns and the names of those columns.