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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
mail2rohitnagar
New Member

Need help with calculated column

I have a usecase to calculate corrected target based on the previous month variance. Below is my scenario

 

Column Name

Values(M1)

Values(M2)Values(M3)
Sales Person NameJohnJohnJohn
ParticularPowerBIPowerBIPowerBI
Month456
Year202520252025
Unique IDJOHN_POWERBI_4_2025JOHN_POWERBI_5_2025JOHN_POWERBI_6_2025
Target (Cr)342
Actual Sales(cr)1.33.10.1
Corrected Target (Cr) (Current month Target+Variance (Prev. Month)) 5.74.6
Variance (Cr) - (Corrected Target - Actual Sales)1.72.64.5

Let me know how to do this in power bi report either as a claulated colum or as a measure

7 REPLIES 7
v-karpurapud
Community Support
Community Support

Hi @mail2rohitnagar 

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. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

Thank you.

v-karpurapud
Community Support
Community Support

Hi @mail2rohitnagar 

Welcome to the Microsoft Fabric Community Forum!


To create a measure for calculating the Corrected Target based on the previous month's variance, implement a DAX formula that dynamically adjusts the current month's target by adding the difference between the previous month's target and actual values, ensuring it supports month-to-month transitions including year rollovers and accurately reflects both row-level and aggregate totals across Sales Person and specific groupings.


Please refer to the attached .pbix file for your reference and share your thoughts.

If this helped solve the issue, please consider marking it “Accept as Solution” and giving a ‘Kudos’ so others with similar queries may find it more easily. If not, please share the details, always happy to help.


Thank you.

mail2rohitnagar
New Member

Thank you for your response. Unfortunately, none of the solution worked. For better understanding of my issue i have made a data set with sample value. Hope this helps

 

Dataset link -  https://docs.google.com/spreadsheets/d/1XHqY2gEVpF9IrqleOmQk52gdwnGLdwuJ/edit?usp=share_link&ouid=10...

Nasif_Azam
Solution Sage
Solution Sage

Hey @mail2rohitnagar ,

To calculate the Corrected Target in Power BI based on the previous month's Variance, you can use DAX either as a calculated column (if the model is at row level per month) or as a measure (if you're working with visuals or aggregations). If you're using a calculated column assume your table is named 'Sales' and columns: SalesPerson, Particular, Month, Year, Target, ActualSales.

 

Step 1: Create a column for Variance:

Variance = 
'Sales'[CorrectedTarget] - 'Sales'[ActualSales]

 

Step 2: Create the Corrected Target column:

CorrectedTarget = 
VAR PrevMonth =
    CALCULATE(
        MAX('Sales'[Month]),
        FILTER(
            'Sales',
            'Sales'[SalesPerson] = EARLIER('Sales'[SalesPerson]) &&
            'Sales'[Particular] = EARLIER('Sales'[Particular]) &&
            'Sales'[Year] = EARLIER('Sales'[Year]) &&
            'Sales'[Month] = EARLIER('Sales'[Month]) - 1
        )
    )

VAR PrevVariance =
    CALCULATE(
        'Sales'[Target] - 'Sales'[ActualSales],
        FILTER(
            'Sales',
            'Sales'[SalesPerson] = EARLIER('Sales'[SalesPerson]) &&
            'Sales'[Particular] = EARLIER('Sales'[Particular]) &&
            'Sales'[Year] = EARLIER('Sales'[Year]) &&
            'Sales'[Month] = PrevMonth
        )
    )

RETURN 'Sales'[Target] + PrevVariance

 

If using a measure, it's more complex because measures are aggregate-level and cannot store previous row context. You can still do it using CALCULATE and FILTER with a measure, but it's less recommended unless used in visuals.

 

For Detailed Information:

Calculated Columns in Power BI

EARLIER Function in DAX

CALCULATE Function in DAX

FILTER Function in DAX

Measures vs Calculated Columns

 

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

Didn't work, getting an error as there are multiple lines returining for the formula. I have update the data set in the thread to better express my scenario

DataNinja777
Super User
Super User

Hi @mail2rohitnagar ,

 

To achieve your desired calculation for a corrected target in Power BI, you should use DAX measures rather than calculated columns. This approach is more efficient and flexible because the calculation is iterative and depends on values from previous time periods. Measures are evaluated dynamically based on the context of your report visuals, making them ideal for this type of time-based analysis.

First, it is essential to have a proper date table in your model, as time intelligence functions rely on it. If you do not have one, you can create a new table using the following DAX expression. You should adjust the start and end dates to fit your data. After creating the table, right-click on it in the Fields pane and select "Mark as date table," choosing the [Date] column.

DateTable =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2025, 1, 1 ), DATE ( 2026, 12, 31 ) ),
    "Year", YEAR ( [Date] ),
    "MonthNumber", MONTH ( [Date] ),
    "MonthName", FORMAT ( [Date], "mmmm" ),
    "YearMonth", FORMAT ( [Date], "yyyy-mm" )
)

Your main data table, which we can call SalesData, will need a Date column to relate to this new DateTable. You can add this as a calculated column in your SalesData table. Then, in the Model view, create a one-to-many relationship between DateTable[Date] and SalesData[Date].

Date = DATE('SalesData'[Year], 'SalesData'[Month], 1)

With the model prepared, you can create the necessary measures. It is good practice to start with explicit base measures for your core values.

Total Target = SUM('SalesData'[Target (Cr)])
Total Actual Sales = SUM('SalesData'[Actual Sales(cr)])

The logic for your Variance is a running total of the difference between the target and actual sales over time. The following measure calculates this cumulative value. It works by summing the [Total Target] - [Total Actual Sales] difference over a modified date context that includes all dates up to the last date of the current period being evaluated in your visual.

Variance (Cr) =
VAR FirstDateInContext =
    CALCULATE ( MIN ( 'SalesData'[Date] ), ALLSELECTED ( 'SalesData' ) )
RETURN
    CALCULATE (
        [Total Target] - [Total Actual Sales],
        FILTER (
            ALLSELECTED ( 'DateTable' ),
            'DateTable'[Date] >= FirstDateInContext
                && 'DateTable'[Date] <= MAX ( 'DateTable'[Date] )
        )
    )

Finally, the Corrected Target measure can be created. This formula calculates the Variance (Cr) from the previous month and adds it to the current month's Total Target. It uses the DATEADD function to shift the calculation context back one month. The COALESCE function is important for handling the very first period, ensuring that a missing previous month's variance is treated as zero.

Corrected Target (Cr) =
VAR PreviousMonthVariance =
    CALCULATE (
        [Variance (Cr)],
        DATEADD ( 'DateTable'[Date], -1, MONTH )
    )
RETURN
    IF (
        NOT ISBLANK ( [Total Target] ),
        [Total Target] + COALESCE ( PreviousMonthVariance, 0 )
    )

To display the results, you can use a Matrix visual in your Power BI report. Place fields like Sales Person Name, Particular, and YearMonth from the DateTable onto the rows. Then, add your measures—Total Target, Total Actual Sales, Corrected Target (Cr), and Variance (Cr)—to the values area to generate the final table.

 

Best regards,

 

tharunkumarRTK
Super User
Super User

@mail2rohitnagar 

You can calcuate previous month value in many ways.

1. PREVIOUSMONTH DAX function - https://dax.guide/previousmonth/

2. Window functions - https://www.sqlbi.com/articles/introducing-window-functions-in-dax/

3. PREVIOUS visual calculation https://dax.guide/previous/

 

It could be difficult for anyone to suggest you the formula without knowing the data model and schema. For further help please share the pbix file with sample data.

 

 

 

 

 

Connect on LinkedIn

 

 

 








Did I answer your question? Mark my post as a solution!
If I helped you, click on the Thumbs Up to give Kudos.

Proud to be a Super User!


PBI_SuperUser_Rank@2x.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors