Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi I have this sample data, I want to remove the last 2 rows of a given set of data. For example in this case I want to remove the selected ones in red because its only allowed to have 2 records per combination
#"sample"
ID1 | ID2 |
1 | 1 |
1 | 2 |
1 | 3 |
1 | 4 |
2 | 1 |
2 | 2 |
3 | 1 |
3 | 2 |
3 | 3 |
I get to these code but its incomplete. I dont know if need another approach or if is possible to iterate each row of the #"sample for distinct ID1s
#"ID1 Table" = Table.SelectColumns(#"sample",{"ID1"}),
#"Distinct ID1 Table" = Table.Distinct(#"ID1 Table"),
.... //Missing code
#"Last records" = Table.SelectRows(table,each [ID1] <> ID1Filter), //ID1Filter is a distinct ID1 from table
#"ID2 from ID1"= Table.SelectRows(table,each [ID1] = ID1Filter),
#"quantity Of ID2" = Table.RowCount(#"ID2fromID1"),
#"Last ID2 fromI D1"= Table.RemoveLastN(#"ID2 from ID1",if #"quantity Of ID2"> 2 then #"quantity Of ID2"- 2 else 0),
#"Removed"= Table.Combine({#"Last records",#"LastID2fromID1"})
Solved! Go to Solution.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeJYHQjLCM4yhrNMwCwjuDojuDpjuJgxihhQbywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID1 = _t, ID2 = _t]),
Grouped = Table.Group(Source, "ID1", {"a", each if Table.RowCount(_) > 2 then Table.FirstN(_, 2) else _}),
#"Expanded a" = Table.ExpandTableColumn(Grouped, "a", {"ID2"}, {"ID2"})
in
#"Expanded a"
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Love the simplicity of your solution!. Thank you so much!
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeJYHQjLCM4yhrNMwCwjuDojuDpjuJgxihhQbywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID1 = _t, ID2 = _t]),
Grouped = Table.Group(Source, "ID1", {"a", each if Table.RowCount(_) > 2 then Table.FirstN(_, 2) else _}),
#"Expanded a" = Table.ExpandTableColumn(Grouped, "a", {"ID2"}, {"ID2"})
in
#"Expanded a"
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.