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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Bimtng
Frequent Visitor

Weird behavior in dax measure

Good afternoon.

 

Please, watch this two measures:

 

Version 1:

 

Anul.Ped.netos € =
VAR fecha = [Fecha últ. pedido]
RETURN
    CALCULATE (
        [Anul.Ped.reales €];
        FILTER (
            'HECHOS Pedidos anulados';
            'HECHOS Pedidos anulados'[Fechaanulacion_ID] <= fecha
        )
    )

 

Version 2:

 

Anul.Ped.netos € =
    CALCULATE (
        [Anul.Ped.reales €];
        FILTER (
            'HECHOS Pedidos anulados';
            'HECHOS Pedidos anulados'[Fechaanulacion_ID] <= [Fecha últ. pedido]
        )
    )

 

They give different results, even though they seem to be absolutely similar. The only difference is the usage of a variable in version 1 to previously load the measure containing a single date.

 

May anybody please help me?

 

Thank you in advance.

2 REPLIES 2
Phil_Seamark
Microsoft Employee
Microsoft Employee

It is to do with context and can be used to your benefit if used well.

 

When you declare and assign a variable, the value assigned from [Fecha últ. pedido] will be relevant for the context at play at that point.

 

In the 2nd example, your calls to [Fecha últ. pedido] take place with a different context (inside the CALCULATE which is converting row context to filter context).

 

But the short answer is, pick the one that works for you and run with that 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks for your reply. Actually, the one that works for me is the version that uses de variable. The other one produces incorrect results, I do not know why. The key is that I was hours trying to find why the version without variable did not work, until I tried the other one that worked.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors