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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Syndicate_Admin
Administrator
Administrator

last value in time minus penultimate

Good afternoon

I have a table in which I would like to calculate a measure that, filtering by the last record loaded, subtracts me from the last value in time, the penultimate. In the capture you will see it clearer.

My first filter is "Month&Year", which is the last value loaded into system and I round it up in BLUE.

I want to get the result of subtracting 100 and 99.22 (=0.78). Rodeo in RED.

Why? because for my last uploaded value, the last record is in August 2021 and I have to subtract the one from the previous month, July 2021.

The measurement is rare but the calculation must be that.

I've thought several things. As it goes based on a date, take the MAX of that date and subtract the value from it when MAX-30 ("last date minus 30 days"). But of course, not every month has 30 days...

Can you think of something?

kikejnt_0-1622471495135.png

1 ACCEPTED SOLUTION

For a card visual try:

Difference =

VAR MaxDate = MAX(Hoja1 [Fecha avance])

VAR PrevDate= CALCULATE(MAX(Hoja1[Fecha avance]), FILTER(Hoja1, Hoja1[Fecha avance] < MaxDate))

RETURN

CALCULATE([Sum value], FILTER(Hoja1, Hoja1 [Fecha avance]  = MaxDate)) - CALULATE([ Sum value], FILTER(Hoja1, Hoja1 [Fecha avance] = PrevDate))





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

7 REPLIES 7
PaulDBrown
Community Champion
Community Champion

Thanks for providing the sample PBIX file. It is really helpful.

 

Ok, so this should measure work for you:

Diferencia vs penultimo =
VAR CurrentDate =
    MAX ( Hoja1[Fecha Avance] ) //Returns the date in the filter context
VAR PreviousDate =
    MAXX (
        FILTER (
            ALL ( Hoja1[Fecha Avance] ),
            Hoja1[Fecha Avance] < CurrentDate
                && NOT ( ISBLANK ( [Sum Value] ) )
        ),
        Hoja1[Fecha Avance]
    ) //Returns the last date previous to the current date in which [sum of value] is not blank
RETURN
    [Sum Value]
        - CALCULATE (
            [Sum Value],
            FILTER ( ALL ( Hoja1[Fecha Avance] ), Hoja1[Fecha Avance] = PreviousDate )
        )

And this is the result:

result.JPG

I've attached the file for you





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thank you so much!

It looks very good.

What if I wanted to put the condition in the formula that I do that same calculation with the last date filter in the field "Month & Year"? That would be perfect.

And beware! That I want this for a card. It's not a table. I want this little number.

kikejnt_0-1622541099202.png

the specifications should be more, right?

nevertheless. It looks good.

For a card visual try:

Difference =

VAR MaxDate = MAX(Hoja1 [Fecha avance])

VAR PrevDate= CALCULATE(MAX(Hoja1[Fecha avance]), FILTER(Hoja1, Hoja1[Fecha avance] < MaxDate))

RETURN

CALCULATE([Sum value], FILTER(Hoja1, Hoja1 [Fecha avance]  = MaxDate)) - CALULATE([ Sum value], FILTER(Hoja1, Hoja1 [Fecha avance] = PrevDate))





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Syndicate_Admin
Administrator
Administrator

Attachment .pbix.

Basically what I want is a measure that I can subtract from the last value in time, the penultimate one. The values I surround. I've tried taking 30 off the maximum value, but obviously it only works for months that have 30 days... And there are 31 and 28 as well.

kikejnt_0-1622530041842.png

PaulDBrown
Community Champion
Community Champion

Please provide sample data or a PBIX file to work with. Thanks!





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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