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.
- Anonymous4 years agoNot applicable
Thanks! looks great both options, I think i am more interested into the 2 option since it would help to have a table which i cna use to set new mesurementes if its need it.
So i tried the second one. My source data is 'Fact-IR_IM Raw data Azure' so i change it...
Seems to be very havy to deal with right? running out of memory?
- tamerj14 years agoCommunity Champion
Anonymous
Do you want the original Wapoint and Waypoint-Actual columns? Actually I just assumed that you want to keep the one with the longest sting. Maybe this has no meaning. We can skip these unnecessary calculations and save alot of formula engine time. What do you think? Shall I update accordingly? On the other hand I would really recommend using the measure. It takes advantage of the existing filter context this it's more efficient and yet complicately dynamic. It depends on what other measures you are going to create and what is the ultimate report you are looking for but most probably we can solve this out.
- Anonymous4 years agoNot applicable
Yes thansk!
Well i need to keep always the column " Waypoint" and next to this as many new "waypoint actual " can came.. so if now the row has on 1 waypoint actual.. that would be 1 reroute... if this has 2 so it would have 1 re route and then 2 reroute... and so on.. NEW ACTUAL WAYPOINT= new column based on extraction date of course ..
Like i show it here
Acltual dataDesired data