Forum Discussion
Adding comparative rows at the bottom of Matrix Visual
- Anonymous1 year ago
Hi rashidanwar ,
Please follow these steps:
1.Use Power Query to create a blank query and perform an "append" operation
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"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 _result3.Final output
Best Regards,
Wenbin Zhou - 1 year ago
I know this is late. But you can have a short look on my solution as well.
Assuming your dataset look like belowthen 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 _ResultStep 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 DAXIF( MAX( ResultTable[Year] ) = "Diff%", "0%","#,##0" )Below screenshot
you can find the pbix file in below link
Hope this will help
Regards,
sanalytics
Hi rashidanwar ,
Please follow these steps:
1.Use Power Query to create a blank query and perform an "append" operation
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"
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
Best Regards,
Wenbin Zhou