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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ptkhoa2110
Helper II
Helper II

Minus 2 measure previous value

Dear All,

 

Could you help me show how to minus between 2 column previous Measure in PowerBI.

 

Source:

ptkhoa2110_0-1600954343710.png

Destination desire

 
 

Untitled-1.jpg

M.ExpectedPre = M.ExpectedValue - Previous(M.Duration)

Any column above are measure type. 

 

Many thanks.

1 ACCEPTED SOLUTION

Hi @ptkhoa2110 

I update my Calculated Column and Measure in your Sample and hope this may help you.

Rank column:

C.Rank = RANKX(FILTER(DemoTracking,DemoTracking[ITEMCODE] = EARLIER(DemoTracking[ITEMCODE])),DemoTracking[TransferID],,ASC,Dense)

Measure:

M.ExpectedPre = 
VAR _Pre =
    CALCULATE (
        [M.ExpectedValue],
        FILTER ( ALL(DemoTracking) ,DemoTracking[ITEMCODE]=MAX(DemoTracking[ITEMCODE])&& DemoTracking[C.Rank] = MAX ( DemoTracking[C.Rank] ) - 1 )
    )
RETURN
    IF ( _Pre = BLANK (), BLANK (), _Pre - [M.Duration] )

Result:

1.png

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

View solution in original post

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @ptkhoa2110 

Due to I don't know your data model, so I have to build a sample table to have a test.

Add a Rank column in this Table.

Rank = RANKX('Table','Table'[M.To Date],,ASC,Dense)

1.png

Due to M.ExpectedPre = M.ExpectedValue - Previous(M.Duration) are all measures, so build measures.

M.Duration = SUM('Table'[3])
M.ExpectedValue = SUM('Table'[4])
M.ExpectedPre = 
VAR _Pre =
    CALCULATE (
        [M.ExpectedValue],
        FILTER ( ALL ( 'Table' ), 'Table'[Rank] = MAX ( 'Table'[Rank] ) - 1 )
    )
RETURN
    IF ( _Pre = BLANK (), BLANK (), _Pre - [M.Duration] )

Result:

2.png

You can download the pbix file from this link: Minus 2 measure previous value

If this reply still couldn't help you solve your problem, please show me your data model and you calculate logic of these three columns. Or you can provide me with your pbix file by you OneDrive for Business. And this may make it easier for me to understand your calculate logic.

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

Hi @ptkhoa2110 

I update my Calculated Column and Measure in your Sample and hope this may help you.

Rank column:

C.Rank = RANKX(FILTER(DemoTracking,DemoTracking[ITEMCODE] = EARLIER(DemoTracking[ITEMCODE])),DemoTracking[TransferID],,ASC,Dense)

Measure:

M.ExpectedPre = 
VAR _Pre =
    CALCULATE (
        [M.ExpectedValue],
        FILTER ( ALL(DemoTracking) ,DemoTracking[ITEMCODE]=MAX(DemoTracking[ITEMCODE])&& DemoTracking[C.Rank] = MAX ( DemoTracking[C.Rank] ) - 1 )
    )
RETURN
    IF ( _Pre = BLANK (), BLANK (), _Pre - [M.Duration] )

Result:

1.png

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Dear @v-rzhou-msft , I don't know what to say, I only know many thanks for your support. That work greate for me. Thanks.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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