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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CL7777
Helper III
Helper III

what is the difference between these two dax calculated columns

These give different answers in my model and I do not understand why. Can someone explain to me the difference? does it have to do with the context transition of Calculate? I have a very simple model in which sales is connected to date as a many to one relationship. Below CODE #2 gives the right answer and CODE #1 gives the wrong answer.

 

CODE # 1

deliverydays=
CALCULATE (COUNTROWS ( 'Date' ),
FILTER (
ALL ( 'Date' ),
'Date'[Date] > Sales[Order Date]
&& 'Date'[Date] < Sales[Delivery Date]
&& 'Date'[Working Day] = "WorkDay" 
        )
)
 
CODE # 2
DeliveryDays =
VAR OrderDate = Sales[Order Date]
VAR DeliveryDate = Sales[Delivery Date]
VAR WorkingDays = FILTER (ALL ( 'Date' ),
'Date'[Date] >= OrderDate
&& 'Date'[Date] <= DeliveryDate
&& 'Date'[Working Day] = "WorkDay"
)
VAR CountWorkingDays = COUNTROWS ( WorkingDays )
RETURN CountWorkingDays


1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @CL7777 ,

 

I have made a sample for your reference, the result should be the same using the two formulas. Please not we should use >= and <= instead of > , < .

 

deliverydays = 
CALCULATE (
    COUNTROWS ( 'Date' ),
    FILTER (
        ALL ( 'Date' ),
        'Date'[Date] >= Sales[Order Date]
            && 'Date'[Date] <= Sales[Delivery Date]
            && 'Date'[Working Day] = "WorkDay"
    )
)

 

 

 

DeliveryDays_ = 
VAR OrderDate = Sales[Order Date]
VAR DeliveryDate = Sales[Delivery Date]
VAR WorkingDays =
    FILTER (
        ALL ( 'Date' ),
        'Date'[Date] >= OrderDate
            && 'Date'[Date] <= DeliveryDate
            && 'Date'[Working Day] = "WorkDay"
    )
VAR CountWorkingDays =
    COUNTROWS ( WorkingDays )
RETURN
    CountWorkingDays

 

Capture.PNG

 

Also attached the pbix .

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @CL7777 ,

 

I have made a sample for your reference, the result should be the same using the two formulas. Please not we should use >= and <= instead of > , < .

 

deliverydays = 
CALCULATE (
    COUNTROWS ( 'Date' ),
    FILTER (
        ALL ( 'Date' ),
        'Date'[Date] >= Sales[Order Date]
            && 'Date'[Date] <= Sales[Delivery Date]
            && 'Date'[Working Day] = "WorkDay"
    )
)

 

 

 

DeliveryDays_ = 
VAR OrderDate = Sales[Order Date]
VAR DeliveryDate = Sales[Delivery Date]
VAR WorkingDays =
    FILTER (
        ALL ( 'Date' ),
        'Date'[Date] >= OrderDate
            && 'Date'[Date] <= DeliveryDate
            && 'Date'[Working Day] = "WorkDay"
    )
VAR CountWorkingDays =
    COUNTROWS ( WorkingDays )
RETURN
    CountWorkingDays

 

Capture.PNG

 

Also attached the pbix .

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
VasTg
Memorable Member
Memorable Member

@CL7777 

 

I guess you are creating the column in Sales table and i believe its the context transition as you said which is filtering the data. Try countx instead of calculate to verify that.

Connect on LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.