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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
F_Reh
Helper V
Helper V

Additional Single Column required for Matrix

Good Morning,

 

I have a Matrix which shows figures for several months:

 

F_Reh_0-1738927247997.png

 

I wish to have an additional column inserted between the last month in the series column (i.e. July 2024) and the Total column, which shows the difference between the last two months (i.e. June 2024 and July 2024). So in the above example the "theorized" single column should display - 45.7%.

 

I tried making a measure and adding it to the Values section,

 

F_Reh_1-1738927849752.png

 

But what happens is it adds a new column (for that measure) for each month (which is not what was intended i.e a single new column calculating the difference only between the two latest months).

 

Kind Regards

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @F_Reh 

To insert a column between Jul-24 and the Total column, you need a disconnected table with a column for the month-year, the desired name for the difference column, and a custom sort value. Additionally, you'll need to create a measure that references the values in this column and includes logic to calculate the difference between the latest and previous month.

danextian_0-1738931486758.png

Period With Difference Measure = 
-- Calculate revenue for the selected period
VAR _PeriodValue =
    CALCULATE (
        [Total Revenue], 
        -- Map the selected period to the Dates table using TREATAS
        TREATAS ( VALUES ( PeriodWithDifference[Period] ), Dates[Month and Year] )
    )

-- Get the latest period in the current context as a formatted string (e.g., "Jan-24")
VAR _LatestPeriod =
    FORMAT ( [Latest Date with Data in the current context], "mmm-yy" )

-- Get the previous period by shifting the latest date back by one month
VAR _PrevPeriod =
    FORMAT (
        EDATE ( [Latest Date with Data in the current context], -1 ), 
        "mmm-yy"
    )

-- Calculate the difference in revenue between the latest and previous periods
VAR _Diff =
    CALCULATE (
        [Total Revenue],
        -- Retrieve revenue for the latest period
        FILTER ( ALL ( Dates ), Dates[Month and Year] = _LatestPeriod )
    )
        - CALCULATE (
            [Total Revenue],
            -- Retrieve revenue for the previous period
            FILTER ( ALL ( Dates ), Dates[Month and Year] = _PrevPeriod )
        )

-- Return the difference if "Difference" is selected, otherwise return the period revenue
RETURN
    IF (
        SELECTEDVALUE ( PeriodWithDifference[Period] ) = "Difference",
        _Diff,
        _PeriodValue
    )

danextian_1-1738931631459.png

Please see the attached sample pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
F_Reh
Helper V
Helper V

Or would it be practical to go for a simpler solution ?

danextian
Super User
Super User

Hi @F_Reh 

To insert a column between Jul-24 and the Total column, you need a disconnected table with a column for the month-year, the desired name for the difference column, and a custom sort value. Additionally, you'll need to create a measure that references the values in this column and includes logic to calculate the difference between the latest and previous month.

danextian_0-1738931486758.png

Period With Difference Measure = 
-- Calculate revenue for the selected period
VAR _PeriodValue =
    CALCULATE (
        [Total Revenue], 
        -- Map the selected period to the Dates table using TREATAS
        TREATAS ( VALUES ( PeriodWithDifference[Period] ), Dates[Month and Year] )
    )

-- Get the latest period in the current context as a formatted string (e.g., "Jan-24")
VAR _LatestPeriod =
    FORMAT ( [Latest Date with Data in the current context], "mmm-yy" )

-- Get the previous period by shifting the latest date back by one month
VAR _PrevPeriod =
    FORMAT (
        EDATE ( [Latest Date with Data in the current context], -1 ), 
        "mmm-yy"
    )

-- Calculate the difference in revenue between the latest and previous periods
VAR _Diff =
    CALCULATE (
        [Total Revenue],
        -- Retrieve revenue for the latest period
        FILTER ( ALL ( Dates ), Dates[Month and Year] = _LatestPeriod )
    )
        - CALCULATE (
            [Total Revenue],
            -- Retrieve revenue for the previous period
            FILTER ( ALL ( Dates ), Dates[Month and Year] = _PrevPeriod )
        )

-- Return the difference if "Difference" is selected, otherwise return the period revenue
RETURN
    IF (
        SELECTEDVALUE ( PeriodWithDifference[Period] ) = "Difference",
        _Diff,
        _PeriodValue
    )

danextian_1-1738931631459.png

Please see the attached sample pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I have attempted the latest suggestion....The issue is there is toggle slicer which allows the units in the Matrix for the Monthly data to be displayed either in percentages or numeric figures....

 

F_Reh_0-1742907333434.png

 

The Parameter Field behind the Toggle is:

 

Parameter = {
    ("<Figures>", NAMEOF('<Data_Table>'[<Measure_Figures>]), 0),
    ("<Percentages>", NAMEOF('<Data_Table>'<Measure_Percentages>), 1)
}

 

So I am not using a single measure equivalent to "Total Revenue" (which you have used within your measure named Period With Difference Measure).

 

So the new single column proposed for the Matrix needs to accommodate interchangeably either [% of Current Month] subtract  [% of Previous Month] or [Total Figure of Current Month] subtract  [Total Figure of Previous Month] - depending on whichever of the Units the Viewer clicks on the toggle slicer.

 

 
mh2587
Super User
Super User

 

Diff_Last_Two_Months = 
VAR LastMonth = MAX('Table'[Month])
VAR SecondLastMonth = CALCULATE(MAX('Table'[Month]), 'Table'[Month] < LastMonth)

VAR LastMonthValue = CALCULATE(SUM('Table'[Value]), 'Table'[Month] = LastMonth)
VAR SecondLastMonthValue = CALCULATE(SUM('Table'[Value]), 'Table'[Month] = SecondLastMonth)

RETURN 
    IF(NOT ISBLANK(SecondLastMonthValue),
       DIVIDE(LastMonthValue - SecondLastMonthValue, SecondLastMonthValue),
       BLANK()
    )
// and then convert this measure to Percentage & add it to matrix on your desire place

 


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors