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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Fcoatis
Post Patron
Post Patron

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:

Forum.png

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.

 

 

 

2 ACCEPTED SOLUTIONS
parry2k
Super User
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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

CNENFRNL
Community Champion
Community Champion

VAR _AntValor = MAXX ( TOPN( 1, _DataM1, Trans[Data] ), Trans[Valor] )

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

VAR _AntValor = MAXX ( TOPN( 1, _DataM1, Trans[Data] ), Trans[Valor] )

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

parry2k
Super User
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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors