Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not 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

 

IDMessageIdEventtypeTimestampSystemTypeId
1101Pack14/02/18 00:00ABC
2102Unpack14/02/18 00:00ABC
3103Unpack14/02/18 01:00ABC
4104Pack14/02/18 01:00ABC
5105Unpack14/02/18 01:00ABC
6101Pack14/02/18 00:00XYZ
7102Unpack14/02/18 00:00XYZ
8104Pack14/02/18 01:00XYZ
9105Pack14/02/18 01:00XYZ

 

I want to compare the rows with the same MessageID.

For example: I am comparing MessageID 101, then all the values like Eventtype, Timestamp are matching for both the systems i.e. ABC and XYZ.

But for the MessageID 105 the value for Eventtype is not matching or both the systems i.e. ABC and XYZ hence this message will not be counted as a MATCH message.

 

Finally i want to show it on the dashboard as

 

14/02/18 00:00          14/02/18 01:00

Count of Messages         Count of Messages

ABC               XYZ          ABC                 XYZ

2                     2               3                     1

 

I require a flag across the above table that will help me to obtain the above result in PowerBI.

Can you please assist me with the same.

Thank you so much in advance.

 

 

1 REPLY 1
stretcharm
Memorable Member
Memorable 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"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.