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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
michael_knight
Post Prodigy
Post Prodigy

Previous rather than MINX

Hi,

 

I recently posted a thread when I needed help converting an Excel theory to Power BI. I got some brilliant help on here, however I need to adjust it.

 

This is what I need to do (diff is the aim)

Resale help 2.PNG

I need to see the difference between an offer and it's prerequisite offer, rather than the very first offer.

 

Originally any offer after the first will check to see what the difference is between the Total In's of the first offer 

diff = 
VAR tb =
    SUMMARIZE (
        ALL ( Theory ),
        'Theory'[Property Name],
        Theory[Date Offer Accepted],
        Theory[Resale?],
        'Theory'[Total IN],
        "T", CONVERT ( 'Theory'[Total IN], INTEGER )
    )
RETURN
    IF (
        ISBLANK ( Theory[Date Offer Accepted] ),
        0,
        'Theory'[Total IN]
            - SUMX (
                FILTER (
                    tb,
                    [Date Offer Accepted]
                        = MINX(  
                            FILTER ( tb , [Property Name] = EARLIER ( Theory[Property Name] ) ),
                            [Date Offer Accepted]
                        )
                        && [Property Name] = EARLIER( Theory[Property Name] )
                ),
                [T]
            )
    )

This is the foruma that was created, and I need to make some amendments to make sure it will show the difference between the previous date rather than the first date.

 

I've made a column which is the intended goal (diff - excel version) which will hopefully help in showing what the aim is 

aim.PNG

 

Here's the PBIX file: 

https://www.dropbox.com/s/6r1v3a3rqztbfec/Help%20-%20Resale.pbix?dl=0

 

Cheers,

Mike

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a column expression that does that.  Note that in your example pbix, I had to change the data type of the Total In column to number.

 

Diff From Prev =
VAR thissale = Theory[Total IN]
VAR thisdate = Theory[Date Offer Accepted]
VAR prevdate =
    CALCULATE (
        MAX ( Theory[Date Offer Accepted] ),
        ALLEXCEPT (
            Theory,
            Theory[Property Name]
        ),
        Theory[Date Offer Accepted] < thisdate
    )
VAR prevsale =
    CALCULATE (
        SUM ( Theory[Total IN] ),
        ALLEXCEPT (
            Theory,
            Theory[Property Name]
        ),
        Theory[Date Offer Accepted] = prevdate
    )
RETURN
    IF (
        ISBLANK ( prevsale ),
        BLANK (),
        thissale - prevsale
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
michael_knight
Post Prodigy
Post Prodigy

Thank you very much, that worked for me @mahoneypat 

 

Thank you too @v-eqin-msft  for helping me also, much appreciated  

v-eqin-msft
Community Support
Community Support

Hi @michael_knight ,

You could try to follow these steps:

 

1. Add a rank column:

rankColumn =
VAR a = [Property Name]
VAR t1 =
    FILTER ( ALL ( 'Theory' ), 'Theory'[Property Name] = a )
RETURN
    RANKX ( t1, RANKX ( t1, [Date Offer Accepted],, ASC, SKIP ),, ASC, SKIP )

2.Create a measure: 

=
VAR _pre =
    CALCULATE (
        MAX ( 'Theory'[Total IN] ),
        FILTER (
            ALLEXCEPT ( Theory, Theory[Property Name] ),
            'Theory'[rankColumn]
                = MAX ( 'Theory'[rankColumn] ) - 1
        )
    )
RETURN
    IF ( _pre = BLANK (), 0, MAX ( 'Theory'[Total IN] ) - _pre )

 

My final output looks like this:
11.26.3.1.PNG

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

mahoneypat
Microsoft Employee
Microsoft Employee

Here is a column expression that does that.  Note that in your example pbix, I had to change the data type of the Total In column to number.

 

Diff From Prev =
VAR thissale = Theory[Total IN]
VAR thisdate = Theory[Date Offer Accepted]
VAR prevdate =
    CALCULATE (
        MAX ( Theory[Date Offer Accepted] ),
        ALLEXCEPT (
            Theory,
            Theory[Property Name]
        ),
        Theory[Date Offer Accepted] < thisdate
    )
VAR prevsale =
    CALCULATE (
        SUM ( Theory[Total IN] ),
        ALLEXCEPT (
            Theory,
            Theory[Property Name]
        ),
        Theory[Date Offer Accepted] = prevdate
    )
RETURN
    IF (
        ISBLANK ( prevsale ),
        BLANK (),
        thissale - prevsale
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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