Forum Discussion
Anonymous
8 years agoNot applicable
Compare 2 rows from the same table
Hi Team, Need your assistance for the below query. I have one table that is fetched in PowerBI as below ID MessageId Eventtype Timestamp SystemTypeId 1 101 Pack 14/02/18 00:00 ...
stretcharm
8 years agoMemorable Member
You can use Grouping and Pivoting in the Query editor
Here is an advanced query script using your sample data. Having the values on the same row means you can also Calculated the difference and filter for only non zero differences.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0AJEBicnZII6JvoGRvqGFgoGBlYEBUMDRyVkpVidayQisEkSG5hUQUGsMVmuMXa0hqloTsFoTbC5AU2kKVmlKlKlmBP0VERkFVmlOhL9gai0IuhWm0hLuVrwqYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, MessageId = _t, Eventtype = _t, Timestamp = _t, SystemTypeId = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"MessageId", Int64.Type}, {"Eventtype", type text}, {"Timestamp", type datetime}, {"SystemTypeId", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"SystemTypeId", "Timestamp"}, {{"Count", each Table.RowCount(_), type number}}),
#"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[SystemTypeId]), "SystemTypeId", "Count", List.Sum),
#"Added Custom" = Table.AddColumn(#"Pivoted Column", "Diff", each [ABC]-[XYZ]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Diff", Int64.Type}})
in
#"Changed Type1"