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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
hackfifi
Helper V
Helper V

Comparing Values from One Column in Same Table

Good Day!

I have the below Sample Data Table/Query "Detail". I would like to acheive the a table visual shown below ("Expected Result") to compare/reconcile values between two Projects. I can easily develop a "Matrix Visual" showing the values only, but cannot work out how to calculate the "Delta". 

Also kindly note "Project" & "Type" are also "Key" tables which has a relationship with "Detail" Table. The user should "only" select two projects. There are over 100 projects.  Cheers in advance!

 

Query.GIF

 

1 ACCEPTED SOLUTION

@hackfifi Ah, details are important. You will want two disconnected Project tables. You can create these using this code:

ProjectSlicerTable1 = DISTINCT('Table'[Project])

ProjectSlicerTable2 = DISTINCT('Table'[Project])

Use these for your slicers. The the code becomes:

Delta measure =
  VAR __Type = MAX('Table'[Type])
  VAR __Compare1 = MAX('ProjectSlicerTable1'[Project])
  VAR __Compare2 = MAX('ProjectSlicerTable2'[Project])
  VAR __A = SUMX(FILTER('Table',[Type]=__Type && [Project] = __Compare1),[Value])
  VAR __B = SUMX(FILTER('Table',[Type]=__Type && [Project] = __Compare2),[Value])
RETURN
  __B - __A


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

I recreated your Data Table and saved it as Book12.xlsx and performed the below transformation in the query editor.

let
Source = Excel.Workbook(File.Contents("C:\Book12.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project", type text}, {"Type", type text}, {"Value", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Project]), "Project", "Value", List.Sum),
#"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,{"A", "B", "C"}),
#"Renamed Columns" = Table.RenameColumns(#"Replaced Value",{{"Type", "Project"}}),
#"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"C"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "Delta (A vs B)", each [B]-[A])
in
#"Added Custom"

 

Below is the resulting table.

bchager6_0-1631467235908.png

 

Hope this helps.

 

Thanks @Anonymous  - Unfortunately, i cannot modify the table in power query as i have over 100 projects. I just provided a sample dataset; and there are over 70+ columns already and there are a lot of measure based on the current power query. I need to work out a "measure". Cheers again for your time.

Greg_Deckler
Community Champion
Community Champion

@hackfifi Seems like something along the lines of:

Delta (A vs B) measure =
  VAR __Type = MAX('Table'[Type])
  VAR __A = SUMX(FILTER('Table',[Type]=__Type && [Project] = "A"),[Value])
  VAR __B = SUMX(FILTER('Table',[Type]=__Type && [Project] = "B"),[Value])
RETURN
  __B - __A


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks for taking time to respond. But my "Project" dropdown (list of 100+ projects) would be dynamic i.e. the user can select ANY two out of 100+ projects. I just provided sample dataset...the current data model has over 70+ columns. 
I am not sure if i need to have two project tables...so user can single select one project from each "Project" filter? i.e. Select Project "A" & Select Project "B"?
 

@hackfifi Ah, details are important. You will want two disconnected Project tables. You can create these using this code:

ProjectSlicerTable1 = DISTINCT('Table'[Project])

ProjectSlicerTable2 = DISTINCT('Table'[Project])

Use these for your slicers. The the code becomes:

Delta measure =
  VAR __Type = MAX('Table'[Type])
  VAR __Compare1 = MAX('ProjectSlicerTable1'[Project])
  VAR __Compare2 = MAX('ProjectSlicerTable2'[Project])
  VAR __A = SUMX(FILTER('Table',[Type]=__Type && [Project] = __Compare1),[Value])
  VAR __B = SUMX(FILTER('Table',[Type]=__Type && [Project] = __Compare2),[Value])
RETURN
  __B - __A


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks Mate - That worked. 

Cheers for your help

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors