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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
DanielKay
Frequent Visitor

Calculation of differences of values between 2 dates

Hello,

 

I'd like to calculate the difference between the amount of entries between two dates.

 

I created this measure to see the differences in stocks between two or more teams:

 

 

 

 

Performance = 
VAR __maxDate = CALCULATE(Maxx(data,data[Date]))
VAR __minDate = CALCULATE(Minx(data,data[Date]))
RETURN
CALCULATE(COUNT(data[Identifier]), FILTER(data,data[Date]=__maxDate)) -
CALCULATE(COUNT(data[Identifier]), FILTER(data,data[Date]=__minDate))

 

 

 

All in all, this measure works like a charm, but the numbers don't add up, when one team hasn't got any entries in __minDate or in __maxDate.

 

For example following dataset:

IdentifierTeamDate
ABC-1Team A12.12.2024
ABC-2Team A12.12.2024
ABC-3Team A12.12.2024
ABC-4Team B12.12.2024
ABC-5Team A12.12.2024
ABC-1Team A19.12.2024
ABC-2Team A19.12.2024
ABC-3Team A19.12.2024
ABC-4Team B19.12.2024
ABC-5Team B19.12.2024

I get the expected Performance: Team B +1, Team A -1

DanielKay_0-1736858777329.png

Let's edit the database, so Team B only exists in the second date.

 

IdentifierTeamDate
ABC-1Team A12.12.2024
ABC-2Team A12.12.2024
ABC-3Team A12.12.2024
ABC-4Team A12.12.2024
ABC-5Team A12.12.2024
ABC-1Team A19.12.2024
ABC-2Team A19.12.2024
ABC-3Team A19.12.2024
ABC-4Team B19.12.2024
ABC-5Team B

19.12.2024

My expected Performance should be: Team B +2, Team A -2

DanielKay_1-1736858922743.png

Somehow my DAX measure can't calculate the numbers correctly. There are no filters applied.

 

Someone got any solution to that problem? Any workarounds? Maybe using a different measure?

 

Thanks in advance.

Kind regards,

Daniel

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @DanielKay 

As there is only one date, both min and max dates are the same and so are values 1 and 2. You can see in the screenshot below that Val1 and Val2 for team B are both 2 so 2-2 = 0. You can add a conditional check in your formula and return only Val1 1 if the condition is true.

Performance3 = 
VAR __maxDate =
    CALCULATE ( MAXX ( data, data[Date] ) )
VAR __minDate =
    CALCULATE ( MINX ( data, data[Date] ) )
VAR __DateTest = __maxDate = __minDate
VAR __Val1 =
    CALCULATE (
        COUNT ( data[Identifier] ),
        FILTER ( data, data[Date] = __maxDate )
    )
VAR __VAl2 =
    CALCULATE (
        COUNT ( data[Identifier] ),
        FILTER ( data, data[Date] = __minDate )
    )
RETURN
    IF ( __DateTest, __Val1, __Val1 - __VAl2 )

danextian_0-1736861681424.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
danextian
Super User
Super User

Hi @DanielKay 

As there is only one date, both min and max dates are the same and so are values 1 and 2. You can see in the screenshot below that Val1 and Val2 for team B are both 2 so 2-2 = 0. You can add a conditional check in your formula and return only Val1 1 if the condition is true.

Performance3 = 
VAR __maxDate =
    CALCULATE ( MAXX ( data, data[Date] ) )
VAR __minDate =
    CALCULATE ( MINX ( data, data[Date] ) )
VAR __DateTest = __maxDate = __minDate
VAR __Val1 =
    CALCULATE (
        COUNT ( data[Identifier] ),
        FILTER ( data, data[Date] = __maxDate )
    )
VAR __VAl2 =
    CALCULATE (
        COUNT ( data[Identifier] ),
        FILTER ( data, data[Date] = __minDate )
    )
RETURN
    IF ( __DateTest, __Val1, __Val1 - __VAl2 )

danextian_0-1736861681424.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
bhanu_gautam
Super User
Super User

@DanielKay , Try using 

DAX
Performance =
VAR __maxDate = CALCULATE(MAX(data[Date]))
VAR __minDate = CALCULATE(MIN(data[Date]))
VAR __maxDateCount = CALCULATE(COUNT(data[Identifier]), FILTER(data, data[Date] = __maxDate))
VAR __minDateCount = CALCULATE(COUNT(data[Identifier]), FILTER(data, data[Date] = __minDate))
RETURN
IF(ISBLANK(__maxDateCount), 0, __maxDateCount) - IF(ISBLANK(__minDateCount), 0, __minDateCount)




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

Proud to be a Super User!




LinkedIn






Sadly, this doesn't work. Same result again. Team A -2; Team B 0.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors