Forum Discussion
Evaluating in DAX Studio
Hello all, need some help here. Here´s a sample data:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdG9CsMgFIbhe3EO5Pzp0Svo2j1kCDRb2kLvf6iNJhD6iYPwvMPhOE2BeKxXSDgM4fbeHs/lVV9M9YR5mIKOla9YDov/xsIdHaAqNywALRnvyAw0McWmYCJ2565opmI5NQVDCZtaUzCVaHTf9bKp+/pZt235BeemSHAgZ6A4MDkCw0FK0oOIgyJZWpBgoCJ98eQ4iKZt+ZRxkIu3LVGBgUn2/n2Eg/pFOczzFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, Banco = _t, Valor = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type date}, {"Banco", type text}, {"Valor", Int64.Type}})
in
#"Changed Type"
I´m trying to evaluate in DAX Studio:
EVALUATE
VAR _Passo1 =
SUMMARIZE ( Trans, Trans[Banco], Trans[Data], Trans[Valor] )
VAR _Passo2 =
ADDCOLUMNS (
_Passo1,
"@Dif",
VAR _AtualBanco = Trans[Banco]
VAR _AtualData = Trans[Data]
VAR _AtualValor = Trans[Valor]
VAR _DataM1 =
FILTER ( _Passo1, Trans[Banco] = _AtualBanco && Trans[Data] < _AtualData )
VAR _AntValor =
MAXX ( _DataM1, Trans[Valor] )
VAR _Dif =
IF ( NOT ISBLANK ( _AntValor ), _AtualValor - _AntValor )
RETURN
_Dif
)
RETURN
_Passo2
Here is my result:
I know the difference (Column @Dif) is wrong because is computing the MAXX of the temporary table _DataM1. My question is: How can I get the last value Trans[Valor] of this temporary table? Please note that I need a solution in evaluation, cause I´m trying to understand querying in DAX Studio. I already created a measure in my model that is functioning. But I strictly need a evaluation statement in DAX Studio as a way of learning.
Thanks in advance.
Fcoatis try this expression:
EVALUATE VAR _Passo1 = SUMMARIZE ( Query1, Query1[Banco], Query1[Data], Query1[Valor] ) VAR _Passo2 = ADDCOLUMNS ( _Passo1, "@Dif", VAR _AtualBanco = Query1[Banco] VAR _AtualData = Query1[Data] VAR _AtualValor = Query1[Valor] VAR _DataM1 = FILTER ( _Passo1, Query1[Banco] = _AtualBanco && Query1[Data] < _AtualData ) VAR _AntValor = CALCULATE ( MAX ( Query1[Valor] ), TOPN ( 1, _DataM1, [Data], DESC ) ) VAR _Dif = IF ( NOT ISBLANK ( _AntValor ), _AtualValor - _AntValor ) RETURN _Dif ) RETURN _Passo2✨ Follow us on LinkedIn
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
VAR _AntValor = MAXX ( TOPN( 1, _DataM1, Trans[Data] ), Trans[Valor] )
2 Replies
- parry2k
Super User
Fcoatis try this expression:
EVALUATE VAR _Passo1 = SUMMARIZE ( Query1, Query1[Banco], Query1[Data], Query1[Valor] ) VAR _Passo2 = ADDCOLUMNS ( _Passo1, "@Dif", VAR _AtualBanco = Query1[Banco] VAR _AtualData = Query1[Data] VAR _AtualValor = Query1[Valor] VAR _DataM1 = FILTER ( _Passo1, Query1[Banco] = _AtualBanco && Query1[Data] < _AtualData ) VAR _AntValor = CALCULATE ( MAX ( Query1[Valor] ), TOPN ( 1, _DataM1, [Data], DESC ) ) VAR _Dif = IF ( NOT ISBLANK ( _AntValor ), _AtualValor - _AntValor ) RETURN _Dif ) RETURN _Passo2✨ Follow us on LinkedIn
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
- CNENFRNL
Community Champion
VAR _AntValor = MAXX ( TOPN( 1, _DataM1, Trans[Data] ), Trans[Valor] )