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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Employee
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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.