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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register 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

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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