Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
2 years ago
Solved

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!

  • Greg_Deckler's avatar
    Greg_Deckler
    2 years ago

    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

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity 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
    

     

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        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
  • Anonymous's avatar
    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.