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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
rashidanwar
Helper III
Helper III

Adding comparative rows at the bottom of Matrix Visual

Hello Community,

I have a following Matrix Visual in Power BI, and I want to add two rows at bottom of it. It should be the difference between 2022/2023 and 2023/2024.

YearNOVDECJANFEBMARAPRMAYJUNJULAUGSEPOCT
2021/2022101214151617181920151619
2022/2023111315212219111618151920
2023/202481419222418141020182322

After adding the two rows the Visual Matrix should look like as follows.

YearNOVDECJANFEBMARAPRMAYJUNJULAUGSEPOCT
2021/2022101214151617181920151619
2022/2023111315212219111618151920
2023/202481419222418141020182322
Diff from last year-31412-13-62342
% Diff-27%8%27%5%9%-5%27%-38%11%20%21%10%


I'll appreciate any help in this regard.

Thank you!
Rashid

2 ACCEPTED SOLUTIONS
v-zhouwen-msft
Community Support
Community Support

Hi @rashidanwar ,

Please follow these steps:

1.Use Power Query to create a blank query and perform an "append" operation

vzhouwenmsft_0-1732761812015.png

let
    Source = Table,
    selectColumn = Table.SelectColumns(Source,{"Month"}),
    distinct = Table.Distinct(selectColumn),
    #"Added Custom" = Table.AddColumn(distinct, "Year", each "Diff from last year")
in
    #"Added Custom"

vzhouwenmsft_1-1732761917259.png

vzhouwenmsft_2-1732761932236.png

vzhouwenmsft_3-1732761964170.png

vzhouwenmsft_4-1732762019666.png

2.Use the following DAX expression to create a measure

MEASURE =
VAR _row =
    SELECTEDVALUE ( Append1[Year] )
VAR _column =
    SELECTEDVALUE ( Append1[Month] )
VAR _difference =
    CALCULATE ( SUM ( Append1[Value] ), 'Append1'[Year] = "2023/2024" )
        - CALCULATE ( SUM ( Append1[Value] ), 'Append1'[Year] = "2022/2023" )
VAR _result =
    IF (
        _row = "Diff from last year",
        FORMAT ( _difference, "0" ),
        IF (
            ISBLANK ( _row ),
            FORMAT (
                DIVIDE (
                    _difference,
                    CALCULATE ( SUM ( Append1[Value] ), 'Append1'[Year] = "2022/2023" )
                ),
                "0%"
            ),
            FORMAT ( SUM ( 'Append1'[Value] ), "0" )
        )
    )
RETURN
    _result

3.Final output

vzhouwenmsft_5-1732764974209.png

 

vzhouwenmsft_6-1732764990718.png

 

Best Regards,
Wenbin Zhou

View solution in original post

sanalytics
Super User
Super User

@rashidanwar 

 

I know this is late.  But you can have a short look on my solution as well.
Assuming your dataset look like below

sanalytics_0-1732794970641.png

then follow below steps

Step 1 : 
create a simple disconnected calculated table by DAX .

ResultTable = 
VAR _1 = 
ROW( "Year","Diff from last Year" )
VAR _2 =
ROW( "Year","Diff%" )
VAR _CombTable = 
UNION(
	VALUES( Source[Year] ),
	_1,_2
)
VAR _Result = 
ADDCOLUMNS(
    _CombTable, "MaxYear",MAX( Source[Year] )
)

RETURN
_Result

Step 2 : Create a consolidated DAX for showing value. Below code. (Assuming you have DAX code for Diff from Last year and Diff %)

Show Value = 
VAR _ValueBase = 
CALCULATE(
    SUM( Source[Value] ),
    TREATAS(
        VALUES( 'ResultTable'[Year] ), Source[Year] 
    ) )
VAR _Result = 
IF(
    MAX( ResultTable[Year] ) = "Diff from last Year",
      CALCULATE(
    [Diff from Last Year],
    TREATAS(
        VALUES( 'ResultTable'[MaxYear] )
        ,Source[Year]
    )
) ,
IF(
    MAX( ResultTable[Year] ) = "Diff%",
       CALCULATE(
    [Diff %],
    TREATAS(
        VALUES( 'ResultTable'[MaxYear] )
        ,Source[Year]
    )
),
_ValueBase
) )
RETURN
_Result


Step 3 : For formatting, go ti Dynamic formatting  and paste below DAX 

IF(
    MAX( ResultTable[Year] ) = "Diff%",
    "0%","#,##0"
)

 

Below screenshot

sanalytics_1-1732795257506.png

 you can find the pbix file in below link

https://we.tl/t-ll7HvM8Gz7

 

Hope this will help

 

Regards,

sanalytics

 

View solution in original post

5 REPLIES 5
rashidanwar
Helper III
Helper III

Thank you so much @sanalytics. This is a good solution, indeed!

sanalytics
Super User
Super User

@rashidanwar 

 

I know this is late.  But you can have a short look on my solution as well.
Assuming your dataset look like below

sanalytics_0-1732794970641.png

then follow below steps

Step 1 : 
create a simple disconnected calculated table by DAX .

ResultTable = 
VAR _1 = 
ROW( "Year","Diff from last Year" )
VAR _2 =
ROW( "Year","Diff%" )
VAR _CombTable = 
UNION(
	VALUES( Source[Year] ),
	_1,_2
)
VAR _Result = 
ADDCOLUMNS(
    _CombTable, "MaxYear",MAX( Source[Year] )
)

RETURN
_Result

Step 2 : Create a consolidated DAX for showing value. Below code. (Assuming you have DAX code for Diff from Last year and Diff %)

Show Value = 
VAR _ValueBase = 
CALCULATE(
    SUM( Source[Value] ),
    TREATAS(
        VALUES( 'ResultTable'[Year] ), Source[Year] 
    ) )
VAR _Result = 
IF(
    MAX( ResultTable[Year] ) = "Diff from last Year",
      CALCULATE(
    [Diff from Last Year],
    TREATAS(
        VALUES( 'ResultTable'[MaxYear] )
        ,Source[Year]
    )
) ,
IF(
    MAX( ResultTable[Year] ) = "Diff%",
       CALCULATE(
    [Diff %],
    TREATAS(
        VALUES( 'ResultTable'[MaxYear] )
        ,Source[Year]
    )
),
_ValueBase
) )
RETURN
_Result


Step 3 : For formatting, go ti Dynamic formatting  and paste below DAX 

IF(
    MAX( ResultTable[Year] ) = "Diff%",
    "0%","#,##0"
)

 

Below screenshot

sanalytics_1-1732795257506.png

 you can find the pbix file in below link

https://we.tl/t-ll7HvM8Gz7

 

Hope this will help

 

Regards,

sanalytics

 

rashidanwar
Helper III
Helper III

@v-zhouwen-msft @Ritaf1983 thank you so much.

v-zhouwen-msft
Community Support
Community Support

Hi @rashidanwar ,

Please follow these steps:

1.Use Power Query to create a blank query and perform an "append" operation

vzhouwenmsft_0-1732761812015.png

let
    Source = Table,
    selectColumn = Table.SelectColumns(Source,{"Month"}),
    distinct = Table.Distinct(selectColumn),
    #"Added Custom" = Table.AddColumn(distinct, "Year", each "Diff from last year")
in
    #"Added Custom"

vzhouwenmsft_1-1732761917259.png

vzhouwenmsft_2-1732761932236.png

vzhouwenmsft_3-1732761964170.png

vzhouwenmsft_4-1732762019666.png

2.Use the following DAX expression to create a measure

MEASURE =
VAR _row =
    SELECTEDVALUE ( Append1[Year] )
VAR _column =
    SELECTEDVALUE ( Append1[Month] )
VAR _difference =
    CALCULATE ( SUM ( Append1[Value] ), 'Append1'[Year] = "2023/2024" )
        - CALCULATE ( SUM ( Append1[Value] ), 'Append1'[Year] = "2022/2023" )
VAR _result =
    IF (
        _row = "Diff from last year",
        FORMAT ( _difference, "0" ),
        IF (
            ISBLANK ( _row ),
            FORMAT (
                DIVIDE (
                    _difference,
                    CALCULATE ( SUM ( Append1[Value] ), 'Append1'[Year] = "2022/2023" )
                ),
                "0%"
            ),
            FORMAT ( SUM ( 'Append1'[Value] ), "0" )
        )
    )
RETURN
    _result

3.Final output

vzhouwenmsft_5-1732764974209.png

 

vzhouwenmsft_6-1732764990718.png

 

Best Regards,
Wenbin Zhou

Ritaf1983
Super User
Super User

Hi @rashidanwar 
You can achieve it with the calculated groups.

Please refer to the linked video :

https://www.youtube.com/watch?v=gNLIaBMXr40

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors