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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Syndicate_Admin
Administrator
Administrator

How to Know the Difference in Values Between 2 Date Range

Hello, good afternoon everyone!

I have a GDP with a date column and a securities column (currency) and I would like to know the monetary difference between 2 selected dates, for example, 01-05-24 and 02-05-24 that tells me that there is a $100 difference between date1 and date2.

The DAX I'm trying is:
Ps: I tried with 2 fixed dates to see if the math works for me, and it did, but when I try to make dynamic dates the formula fails.

Difference Between Days =
VAR SelectedDate1 = DATE(2024,5,1)
VAR SelectedDate2 = DATE(2024,5,2)
VAR TotalValueDay1 = CALCULATE(SUM(Table[Valor Total Prenda]), Table[Fecha] = SelectedDate1)
VAR TotalValueDay2 = CALCULATE(SUM(Table[Valor Total Prenda]), Table[Fecha] = SelectedDate2)
RETURN
TotalValueDay2 - TotalValueDay1

This is the dynamic formula that does not work for me.

Difference Between Days =
VAR SelectedDate1 = MIN(Table[Fecha])
VAR SelectedDate2 = MAX(Table[Fecha])
VAR TotalValueDay1 = CALCULATE(SUM(Table), Table[Date] = SelectedDate1)
VAR TotalValueDay2 = CALCULATE(SUM(Table), Table[Date] = SelectedDate2)
RETURN
TotalValueDay2 - TotalValueDay1

I've tried this way as well, but I'm not getting results.

Difference Between Days =
VAR SelectedDate1 = SELECTEDVALUE(Mayo_24[Fecha])
VAR SelectedDate2 = SELECTEDVALUE(Mayo_24[Fecha])
VAR TotalValueDay1 = CALCULATE(SUM(Mayo_24[Total Pledge Value]), Mayo_24[Date] = SelectedDate1)
VAR TotalValueDay2 = CALCULATE(SUM(Mayo_24[Total Pledge Value]), Mayo_24[Date] = SelectedDate2)
RETURN
TotalValueDay2 - TotalValueDay1

Thank you!

PBI.jpg

1 ACCEPTED SOLUTION

@CatuabaSelvagem My bad:

Difference Between Days =
VAR SelectedDate1 = MINX(ALLSELECTED(Table),[Fecha])
VAR SelectedDate2 = MAXX(ALLSELECTED(Table),[Fecha])
VAR TotalValueDay1 = CALCULATE(SUM(Table), Table[Date] = SelectedDate1)
VAR TotalValueDay2 = CALCULATE(SUM(Table), Table[Date] = SelectedDate2)
RETURN
TotalValueDay2 - TotalValueDay1


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

4 REPLIES 4
Anonymous
Not applicable

Hi,@CatuabaSelvagem ,I am glad to help you.
Hello,@Greg_Deckler,

thanks for your concern about this issue.

Your answer is excellent.
Have you solved your problem?
If you have already found a suitable solution, I hope you will share it or accept the existing one, and if you have not yet solved it, could you provide more information that would be helpful in solving your problem.

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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

Greg_Deckler
Community Champion
Community Champion

@Syndicate_Admin I'm thinking you need to use ALLSELECTED here like this:

 

Difference Between Days =
VAR SelectedDate1 = MINX(ALLSELECTED(Table[Fecha]))
VAR SelectedDate2 = MAXX(ALLSELECTED(Table[Fecha]))
VAR TotalValueDay1 = CALCULATE(SUM(Table), Table[Date] = SelectedDate1)
VAR TotalValueDay2 = CALCULATE(SUM(Table), Table[Date] = SelectedDate2)
RETURN
TotalValueDay2 - TotalValueDay1

 



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...

Hola @Syndicate_Admin !

Thanks for your help but I'm still getting an error in the function... He says that I lack arguments.

CatuabaSelvagem_0-1718209657875.png

@CatuabaSelvagem My bad:

Difference Between Days =
VAR SelectedDate1 = MINX(ALLSELECTED(Table),[Fecha])
VAR SelectedDate2 = MAXX(ALLSELECTED(Table),[Fecha])
VAR TotalValueDay1 = CALCULATE(SUM(Table), Table[Date] = SelectedDate1)
VAR TotalValueDay2 = CALCULATE(SUM(Table), Table[Date] = SelectedDate2)
RETURN
TotalValueDay2 - TotalValueDay1


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
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.