Forum Discussion
Help adding custom columns to matrix (based off the output, not the raw data)
- 8 months ago
You have 2 options here:
1) Create a measure that can be used in every visual in your report.
QoQ % Change = VAR CurrentQ = [Value] VAR PrevQ = CALCULATE ( [Value], DATEADD ( 'Date'[Date], -1, QUARTER ) ) RETURN IF ( NOT ISBLANK ( PrevQ ), DIVIDE ( CurrentQ - PrevQ, PrevQ ) )2) Create a "Visual Calculation" as below which is going to work only with the visual that the calculation has been made.
QoQ % (visual) = VAR Prev = PREVIOUS ( [Value], COLUMNS ) RETURN DIVIDE ( [Value] - Prev, Prev ) - 8 months ago
Hi tridino
Power BI doesn’t work like Excel where you can “add a calculated column” directly on top of a visual’s output. Matrix/visuals in Power BI are designed for visualization of the model, and their layout options are relatively rigid: the Columns/Rows structure is meant to be symmetric, driven by fields and measures, not by manually inserting any custom element anywhere you want.
In your case, you’re trying to display a non-symmetric layout (values for quarters, plus % deltas only after specific quarters, and not after others). That’s not something the Matrix can “just do” by itself.
A common workaround is to “bend the rules” by creating a disconnected helper table that defines the exact column headers and order you want (e.g., Q1, Q2, %Δ2-1, Q3, %Δ3-2, Q4, %Δ4-3, Total) and then use one measure that switches between returning the quarter value or the delta value based on the selected helper-table header.
Important note: each delta header must be unique per quarter pair (e.g., %Δ2-1, %Δ3-2, %Δ4-3). If deltas are not uniquely labeled, you won’t be able to distinguish which delta calculation should run for which “delta column”, and the measure won’t be able to separate them correctly.
High-level steps:
Create a disconnected helper table (no relationship) with:
Quarter
Label (Q1/Q2/%Δ2-1/…/Total)
Sort (to control the exact column order)
Example helper table:
Matrix Helper =
DATATABLE (
"Quarter", INTEGER,
"Label", STRING,
"Sort", INTEGER,
{
{ 1, "Q1", 10 },
{ 2, "Q2", 20 },
{ 2, "%Δ2-1", 25 },
{ 3, "Q3", 30 },
{ 3, "%Δ3-2", 35 },
{ 4, "Q4", 40 },
{ 4, "%Δ4-3", 45 },
{ 0, "Total", 90 }
}
)
Then set Label to “Sort by” = Sort.Create a base measure:
Amount :=
SUM ( 'Table'[Amount] )
Create a single measure for the Matrix that returns either:the selected quarter value, or
the QoQ delta for the relevant quarter pair
Matrix Value :=
VAR label = SELECTEDVALUE ( 'Matrix Helper'[Label] )
VAR q = SELECTEDVALUE ( 'Matrix Helper'[Quarter] )VAR valQ =
IF ( q >= 1 && q <= 4,
CALCULATE ( [Amount], 'Table'[Quarter] = q )
)VAR valPrev =
IF ( q >= 2 && q <= 4,
CALCULATE ( [Amount], 'Table'[Quarter] = q - 1 )
)RETURN
SWITCH (
TRUE(),
label = "Total", [Amount],
LEFT ( label, 1 ) = "Q", valQ,
LEFT ( label, 2 ) = "%Δ", DIVIDE ( valQ - valPrev, valPrev ),
BLANK()
)
Build the Matrix:Rows: Year (from your fact table)
Columns: Matrix Helper[Label]
Values: Matrix Value
This gives you the exact “custom column placement” effect you’re used to in Excel, but in a way that fits Power BI’s modeling + measure paradigm.
(Optional) Formatting: If you want integers for quarter values and one-decimal % for delta columns, you’ll need Dynamic Format Strings (best option) or a text formatting workaround.
Result:
The pbix with the example is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
- 8 months ago
Hi tridino
This solution assumes that you are using a dedicated dates/calendar table which is one of the best practices.
Create a disconnected table containing, the quarter and delta rows column plus other helper columns
Power BI's interface doesn't allow a distinct value to be sorted multiple times thus the need for Period2 which is what will be used in a visual.
Create this measure to get the QoQ variance %
QoQ % = VAR _prev = CALCULATE ( [Total Revenue], PREVIOUSQUARTER ( Dates[Date] ) ) VAR _diff = [Total Revenue] - _prev RETURN DIVIDE ( _diff, _prev )Create this measure:
Quarter Delta Measure = VAR _quarter = CALCULATE ( [Total Revenue], TREATAS ( VALUES ( QuarterDelta[Quarter] ), Dates[Quarter (Number)] ) ) VAR _QoQ = CALCULATE ( [QoQ %], TREATAS ( VALUES ( QuarterDelta[Quarter] ), Dates[Quarter (Number)] ) ) VAR _Total = IF ( not(HASONEVALUE(QuarterDelta[Sort])), [Total Revenue]) RETURN SWITCH ( SELECTEDVALUE ( QuarterDelta[Category] ), "Q", _quarter, "Delta", _QoQ, _Total )Dynamically format this measure with dynamic format strings.
Use the Period2 column from QuarterDelta table and the year column from Dates/Calendar table. Add the measure
Please see the attached pbix.
Hi tridino,
I would also take a moment to thank Ritaf1983 , danextian for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Regards,
Community Support Team.
Hi tridino,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.
Regards,
Community Support Team.