The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi,
I am trying to create DAX measures to get values from previous transaction dates. On left side is Transactions table where is should be able to calculate LTR and EUR values from previous transaction dates. My goal is on right side where I have marked with colours the results which I would like to get ("Previous Ltr" and "Previos EUR"). I have spent so many hours trying to get this working so it would so great if someone could help me?
In addtition this case linked to quite big dataset so I would like to know if it is better to create calculated columns for this? Or are we able to solve this with measure only?
Many thanks for your support in advance!
Solved! Go to Solution.
Hi, @K_LLI
I prefer to use calculated column as below:
C_Prvevious Eur =
CALCULATE (
MAX ( Transactions[Eur] ),
Transactions,
Transactions[Date] < EARLIER ( Transactions[Date] ),
Transactions[Project] = EARLIER ( Transactions[Project] )
)
C_Prvevious Ltr =
CALCULATE (
MAX ( Transactions[Ltr] ),
Transactions,
Transactions[Date] < EARLIER ( Transactions[Date] ),
Transactions[Project] = EARLIER ( Transactions[Project] )
)
You can also try measure as below:
M_Prvevious Eur =
VAR previousdate =
CALCULATE (
MAX ( Transactions[Date] ),
FILTER (
ALLEXCEPT ( Transactions, Transactions[Project] ),
Transactions[Date] < MAX ( Transactions[Date] )
)
)
RETURN
CALCULATE (
MAX ( Transactions[Eur] ),
FILTER ( ALLEXCEPT( Transactions,Transactions[Project]), Transactions[Date] = previousdate )
)
M_Prvevious Ltr =
VAR previousdate =
CALCULATE (
MAX ( Transactions[Date] ),
FILTER (
ALLEXCEPT ( Transactions, Transactions[Project] ),
Transactions[Date] < MAX ( Transactions[Date] )
)
)
RETURN
CALCULATE (
MAX ( Transactions[Ltr] ),
FILTER ( ALLEXCEPT( Transactions,Transactions[Project]), Transactions[Date] = previousdate )
)
Please check my attached pbix file for more details.
Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @K_LLI
I prefer to use calculated column as below:
C_Prvevious Eur =
CALCULATE (
MAX ( Transactions[Eur] ),
Transactions,
Transactions[Date] < EARLIER ( Transactions[Date] ),
Transactions[Project] = EARLIER ( Transactions[Project] )
)
C_Prvevious Ltr =
CALCULATE (
MAX ( Transactions[Ltr] ),
Transactions,
Transactions[Date] < EARLIER ( Transactions[Date] ),
Transactions[Project] = EARLIER ( Transactions[Project] )
)
You can also try measure as below:
M_Prvevious Eur =
VAR previousdate =
CALCULATE (
MAX ( Transactions[Date] ),
FILTER (
ALLEXCEPT ( Transactions, Transactions[Project] ),
Transactions[Date] < MAX ( Transactions[Date] )
)
)
RETURN
CALCULATE (
MAX ( Transactions[Eur] ),
FILTER ( ALLEXCEPT( Transactions,Transactions[Project]), Transactions[Date] = previousdate )
)
M_Prvevious Ltr =
VAR previousdate =
CALCULATE (
MAX ( Transactions[Date] ),
FILTER (
ALLEXCEPT ( Transactions, Transactions[Project] ),
Transactions[Date] < MAX ( Transactions[Date] )
)
)
RETURN
CALCULATE (
MAX ( Transactions[Ltr] ),
FILTER ( ALLEXCEPT( Transactions,Transactions[Project]), Transactions[Date] = previousdate )
)
Please check my attached pbix file for more details.
Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
I added date from transactions table and date from Date table to report and now it is shifting the calculation to next day (1.5.2020 -> 2.5.2020). The calculation should be shifted to next transaction date (1.5.2020 -> 4.5.2020) as shown in my first post. Can anyone help?
I have joined my calendar table to this transaction table and marked is as date table.
Thanks for the support @amitchandak! do you find any solutions to this?
Thank you for your support! Regardin this part:
@K_LLI , with help from a date table
Last Day Non Continuous = CALCULATE([ltr],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))
Last Day Non Continuous EUR = CALCULATE([Eur],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
76 | |
66 | |
52 | |
50 |
User | Count |
---|---|
121 | |
118 | |
77 | |
64 | |
63 |