The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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!
Solved! Go to 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
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.
@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
Hola @Syndicate_Admin !
Thanks for your help but I'm still getting an error in the function... He says that I lack arguments.
@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
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
12 | |
8 | |
8 |