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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
simber
Helper I
Helper I

How to calculate difference of two categories at same time index?

I have a table A that looks like this:

 

TimeValueService
2022-01-0110Service A
2022-01-015Service B
2022-01-028Service A
2022-01-027Service B
2022-01-034Service A
2022-01-033Service B

 

How do I calculate a column that takes the difference for Service A and Service B at each timestep? Either that the result is in a new column in Table A or in a entierly new Table B.

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @simber ,

 

Easiest way is pivot table in Power Query like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI1MAQiJR0lQwMgEZxaVJaZnKrgqBSrgyZviiTthCptBJSywK0bJG2OW7cxUMoEt26QtDGq7lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Value = _t, Service = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type date}, {"Value", Int64.Type}, {"Service", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Service]), "Service", "Value", List.Sum)
in
    #"Pivoted Column"

vjaywmsft_0-1666838254178.png

Then you could directly create a column use [Service A] - [Service B].

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

2 REPLIES 2
v-jayw-msft
Community Support
Community Support

Hi @simber ,

 

Easiest way is pivot table in Power Query like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI1MAQiJR0lQwMgEZxaVJaZnKrgqBSrgyZviiTthCptBJSywK0bJG2OW7cxUMoEt26QtDGq7lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Value = _t, Service = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type date}, {"Value", Int64.Type}, {"Service", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Service]), "Service", "Value", List.Sum)
in
    #"Pivoted Column"

vjaywmsft_0-1666838254178.png

Then you could directly create a column use [Service A] - [Service B].

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@simber , refer this

Compare Categorical Data Using Slicers - Compare two Brands: https://youtu.be/exN4nTewgbc

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.