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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ak77
Post Patron
Post Patron

Add a Difference Row for a group

Hi All,

 

i have following requirement: Pic 1 is the table source and QTD,YTD and Calendar 1 yr measures  are calculated . The User wants to add a Row "Difference" for Each group (A,Abenchmark),(B,Bbenchmark) and calclate the difference as in Fig 2. Please help to transpose this 

Pic 1:

HeaderQTDYTDCalendar 1 yr
A1305
Abenchmark2206
B353
Bbenchmark4157
C5233
Cbenchmark6444
D732
Dbenchmark8171

 

Pic 2:

HeaderQTDYTDCalendar 1 yr
A1305
Abenchmark2206
Difference-110-1
B353
Bbenchmark4157
Difference-1-10-4
C5233
Cbenchmark6444
Difference-1-21-1
D732
Dbenchmark8171
Difference-1-141
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ak77 ,

 

Due to I don't know your data model, I create a sample to have a test.

Here I suggest you to create a Header Group table and create a relationship between it with your Fact table.

QTY with difference =
IF (
    HASONEVALUE ( 'Header Group'[Header] ),
    [M_QTY],
    CALCULATE ( [M_QTY], 'Header Group'[Sort] = 1 )
        - CALCULATE ( [M_QTY], 'Header Group'[Sort] = 2 )
)
YTD with difference = 
IF (
    HASONEVALUE ( 'Header Group'[Header] ),
    [M_YTD],
    CALCULATE ( [M_YTD], 'Header Group'[Sort] = 1 )
        - CALCULATE ( [M_YTD], 'Header Group'[Sort] = 2 )
)
Calendar 1 yr with difference = 
IF (
    HASONEVALUE ( 'Header Group'[Header] ),
    [M_Calendar 1 yr],
    CALCULATE ( [M_Calendar 1 yr], 'Header Group'[Sort] = 1 )
        - CALCULATE ( [M_Calendar 1 yr], 'Header Group'[Sort] = 2 )
)

Then create a Matrix visual > Turn of Stepped layout > Turn on the Per row level

>Turn of show subtotal for row level group > Change the subtotal name for row level Header.

vrzhoumsft_0-1690188237041.png

Result is as below.

vrzhoumsft_1-1690188266364.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @ak77 ,

 

Due to I don't know your data model, I create a sample to have a test.

Here I suggest you to create a Header Group table and create a relationship between it with your Fact table.

QTY with difference =
IF (
    HASONEVALUE ( 'Header Group'[Header] ),
    [M_QTY],
    CALCULATE ( [M_QTY], 'Header Group'[Sort] = 1 )
        - CALCULATE ( [M_QTY], 'Header Group'[Sort] = 2 )
)
YTD with difference = 
IF (
    HASONEVALUE ( 'Header Group'[Header] ),
    [M_YTD],
    CALCULATE ( [M_YTD], 'Header Group'[Sort] = 1 )
        - CALCULATE ( [M_YTD], 'Header Group'[Sort] = 2 )
)
Calendar 1 yr with difference = 
IF (
    HASONEVALUE ( 'Header Group'[Header] ),
    [M_Calendar 1 yr],
    CALCULATE ( [M_Calendar 1 yr], 'Header Group'[Sort] = 1 )
        - CALCULATE ( [M_Calendar 1 yr], 'Header Group'[Sort] = 2 )
)

Then create a Matrix visual > Turn of Stepped layout > Turn on the Per row level

>Turn of show subtotal for row level group > Change the subtotal name for row level Header.

vrzhoumsft_0-1690188237041.png

Result is as below.

vrzhoumsft_1-1690188266364.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi @Anonymous , Thanks for reply

 

Is this possible with Table Vizualization? Can you please help

@Anonymous , Please help if possible on this

Anonymous
Not applicable

Hi @ak77 ,

 

As far as I know, Power BI doesn't support us to show results in hierarchy level. Matrix visual should be a better way.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

foodd
Super User
Super User

How to Get Your Question Answered Quickly   meaning please add your work-in-progress Power BI Desktop file, and data source in Excel format.   Please format any DAX measures with short lines for the benefit of the reader.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors