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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
RAKESH1986
Helper II
Helper II

Difference of Two column

Hi All,

@Anonymous 

I am new to power bi, so need your help to solve my below problem.

 

PW attribute is my week no and the corresponding value in the PW value field...PW values are duplicate --each date has this value

RAKESH1986_0-1672215231042.png

 

2. here you can see I am getting a sum of these values in the matrix table.

 

RAKESH1986_1-1672215383880.png

 

 

3. now I need to show the difference between each week's value

PW01 = 0

PW02= 1.23-.48

PW03= 2.-1.3

 

Could you help me how to solve this...this new value needs to be stored in another column either in the same or a new table...new measure or column does not matter.

 

pls, help.

 

thanks

 

 

 

2 ACCEPTED SOLUTIONS
MFelix
Super User
Super User

Hi @RAKESH1986 ,

 

Best option is to create a column with only the week number and add the following measure to your model:

 

Previous Week =
VAR PWVALUESSELECTD =
   MAX ( 'Table'[PwAttribute] ) 
RETURN
    SUM ( 'Table'[Value] )
        - SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[PwAttribute] = PWVALUESSELECTD - 1 ),
            'Table'[Value]
        )

 

If you want to keep the format try the following code:

Previous Week =
VAR PWVALUESSELECTD =
    RIGHT ( MAX ( 'Table'[PwAttribute] ), LEN ( MAX ( 'Table'[PwAttribute] ) ) - 2 )
RETURN
    SUM ( 'Table'[Value] )
        - SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[PwAttribute] = "PW" & PWVALUESSELECTD - 1 ),
            'Table'[Value]
        )

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

HiraNegi
Resolver II
Resolver II

Hi,

 

You may create measure like below.

 

LastWeekVariance =
VAR vWeekNum = MAX ( MatrixDiff[WeekNum]) - 1
var vRSum = CALCULATE(SUM(MatrixDiff[Value]), ALLEXCEPT(MatrixDiff, MatrixDiff[Attribute]), MatrixDiff[WeekNum] =vWeekNum)
Return
sum(MatrixDiff[Value]) - vRSum

 

HiraNegi_0-1672286679135.png

 

Hope this helps.

 

 

 

View solution in original post

2 REPLIES 2
HiraNegi
Resolver II
Resolver II

Hi,

 

You may create measure like below.

 

LastWeekVariance =
VAR vWeekNum = MAX ( MatrixDiff[WeekNum]) - 1
var vRSum = CALCULATE(SUM(MatrixDiff[Value]), ALLEXCEPT(MatrixDiff, MatrixDiff[Attribute]), MatrixDiff[WeekNum] =vWeekNum)
Return
sum(MatrixDiff[Value]) - vRSum

 

HiraNegi_0-1672286679135.png

 

Hope this helps.

 

 

 

MFelix
Super User
Super User

Hi @RAKESH1986 ,

 

Best option is to create a column with only the week number and add the following measure to your model:

 

Previous Week =
VAR PWVALUESSELECTD =
   MAX ( 'Table'[PwAttribute] ) 
RETURN
    SUM ( 'Table'[Value] )
        - SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[PwAttribute] = PWVALUESSELECTD - 1 ),
            'Table'[Value]
        )

 

If you want to keep the format try the following code:

Previous Week =
VAR PWVALUESSELECTD =
    RIGHT ( MAX ( 'Table'[PwAttribute] ), LEN ( MAX ( 'Table'[PwAttribute] ) ) - 2 )
RETURN
    SUM ( 'Table'[Value] )
        - SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[PwAttribute] = "PW" & PWVALUESSELECTD - 1 ),
            'Table'[Value]
        )

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors