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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Calvin69
Helper III
Helper III

Generated Income based on a Variable

Hi everyone,😊

Thank you in advance for attempting to read through this and for any help that you could provide me with.

I am trying to build a measure or a column that would allow me to do the following:

Table:

DateTenantStart ReviewEndRent
01/01/2019Vacant01/10/2019 01/10/20210
01/01/2020Voda01/01/2020 01/10/202010000
01/01/2020Hitash15/11/202001/06/202101/10/202115000
01/01/2020Sports ltd01/01/202015/06/202131/12/20215000
01/07/2021Vacant01/10/2019 01/10/20210
01/07/2021Voda15/11/2020 01/10/202110000
01/07/2021Hitash15/11/2020 01/10/202117000
01/07/2021Sports ltd01/01/202001/11/202131/12/20217000

Target: Total of "4000" should appear based on the following logic

 On the 01/07/2021
 If new review date is Blank or Greater than previous review date and the Tenant Name is the same then the following should take place
HitashNew Rent Value (17000) - Old Rent Value (15000) = 2000
Sports ltdNew Rent Value (7000) - Old Rent Value (5000) = 2000
 Total Rent difference = 2000 + 2000 = 4000

 

Thanks

H

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Calvin69 Made a few assumptions along the way but maybe this:

Measure = 
    VAR __Table = 'Table4'
    VAR __MaxDate = MAX('Table4'[Date])
    VAR __PreviousDate = MAXX(FILTER('Table4',[Date]<__MaxDate),[Date])
    VAR __MaxDateTable = FILTER(__Table,[Date]=__MaxDate)
    VAR __PreviousDateTable = FILTER(__Table,[Date]=__PreviousDate)
    VAR __FinalTable = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                __MaxDateTable,
                "__Include",
                        VAR __Review = [Review]
                    RETURN
                        IF(ISBLANK([Review]) || COUNTROWS(FILTER(__PreviousDateTable,[Review]<__Review))>0,1,0)
            ),
            "__Diff",
                    VAR __Tenant = [Tenant]
                RETURN
                    IF([__Include]=1,[Rent] - MAXX(FILTER(__PreviousDateTable,[Tenant]=__Tenant),[Rent]),0)
        )
RETURN
    SUMX(FILTER(__FinalTable,[__Include]=1),[__Diff])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@Calvin69 Made a few assumptions along the way but maybe this:

Measure = 
    VAR __Table = 'Table4'
    VAR __MaxDate = MAX('Table4'[Date])
    VAR __PreviousDate = MAXX(FILTER('Table4',[Date]<__MaxDate),[Date])
    VAR __MaxDateTable = FILTER(__Table,[Date]=__MaxDate)
    VAR __PreviousDateTable = FILTER(__Table,[Date]=__PreviousDate)
    VAR __FinalTable = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                __MaxDateTable,
                "__Include",
                        VAR __Review = [Review]
                    RETURN
                        IF(ISBLANK([Review]) || COUNTROWS(FILTER(__PreviousDateTable,[Review]<__Review))>0,1,0)
            ),
            "__Diff",
                    VAR __Tenant = [Tenant]
                RETURN
                    IF([__Include]=1,[Rent] - MAXX(FILTER(__PreviousDateTable,[Tenant]=__Tenant),[Rent]),0)
        )
RETURN
    SUMX(FILTER(__FinalTable,[__Include]=1),[__Diff])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

Spot on mate, wonderful and thank you so much.

 

Just wondering why do you add __ before each variable name?

 

H

@Calvin69 Best explained as old habit I suppose. I found it advantageous to flag things I created versus what is actually in the data model. Comes in particularly handly when using ADDCOLUMNS and more complex measures as it can become a bit confusing to figure out what is being referred to in what context. I use a double underscore because it fits the rhythm of my typing better. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.