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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Diagonal Calculation, Dividing one month by prior month but using a different account

Hi there,

Here is a simple view of the sample data

Diagonal Calc.png

 

I want to create a measure in PBI that for account B in Month 2 I divide that by Account A in Month 1 (which equals 2).  Then i want to carry that on for month 3 and divide 300/200 (Account C month 3 by Account B month 2).

 

I have been scratching my head how to figure this out.  Can anyone please help?

 

Thanks!


GZ

2 ACCEPTED SOLUTIONS
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

Just try this formula:

Measure 3 = 
VAR _lastvalue =
    CALCULATE (
        MAX ( 'Table'[Month] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Month] < MAX ( 'Table'[Month] ) )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ) ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Month] = _lastvalue )
        )
    )

Result:

2.JPG

here is pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
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

hi, @Anonymous 

If so, you need to add an index/rank column for Account column to determine which Account is prior of the same month.

Otherwise how do you know the prior account of "B" is "A" not "D".

So adjust the formula as below:

Step1:

Create an index/rank column for Account column.

Step2:

Measure 3 = 
VAR _lastvalue =
    CALCULATE (
        MAX ( 'Table'[Month] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Month] < MAX ( 'Table'[Month] ) )
    )
var _lastAccount=
    CALCULATE (
        MAX ( 'Table'[Account] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] < MAX ( 'Table'[Index]) )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ) ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Month] = _lastvalue &&'Table'[Account]=_lastAccount)
        )
    )

Result:

 1.JPG

 

here is new pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
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

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

Just try this formula:

Measure 3 = 
VAR _lastvalue =
    CALCULATE (
        MAX ( 'Table'[Month] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Month] < MAX ( 'Table'[Month] ) )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ) ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Month] = _lastvalue )
        )
    )

Result:

2.JPG

here is pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi there,

This works for the smaller data set but if i expand it a bit it doesn't.  The issue is that the account changes.  Please see below when I use your measure.  See below on what the measure looks like if i expand the data set.

 

 

Diagonal Calcv2.png

The calculation should actually be the below (this one done in excel)

 

Diagonal Calcv2 excel.png

 

Thanks for your help!

hi, @Anonymous 

If so, you need to add an index/rank column for Account column to determine which Account is prior of the same month.

Otherwise how do you know the prior account of "B" is "A" not "D".

So adjust the formula as below:

Step1:

Create an index/rank column for Account column.

Step2:

Measure 3 = 
VAR _lastvalue =
    CALCULATE (
        MAX ( 'Table'[Month] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Month] < MAX ( 'Table'[Month] ) )
    )
var _lastAccount=
    CALCULATE (
        MAX ( 'Table'[Account] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] < MAX ( 'Table'[Index]) )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ) ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Month] = _lastvalue &&'Table'[Account]=_lastAccount)
        )
    )

Result:

 1.JPG

 

here is new pbix file, please try it.

 

Best Regards,

Lin

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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