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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ollie2110
Frequent Visitor

DAX code wont pick up columns despite being in the source data.

I'm creating a DAX measure which calculates whether email response times were within bussiness hours. The first section is this, 

SameDay = IF(
    FORMAT([Received Date], "YYYY-MM-DD") = FORMAT([First Itinerary Date], "YYYY-MM-DD"),
    TRUE,
    FALSE
)

However the code wont find the listed columns "Received Date" or "First Itinerary Date" despite both being in the source data. 

 

 

ollie2110_0-1721357520960.png

 

2 REPLIES 2
tamerj1
Super User
Super User

Hi @ollie2110 
This can be be created as a calculated column

SameDay =
FORMAT ( 'Table'[Received Date], "YYYY-MM-DD" ) = FORMAT ( 'Table'[First Itinerary Date], "YYYY-MM-DD" )

Measures don't have direct access to the row context. It depends on what are you trying to accomplish, but in general, in order to get access to row context when creating measures you need first to create it. For example if you wish to have it as a filter you can write

Measure2 =
CALCULATE (
    [Measure1],
    -- or expression
    FILTER (
        'Table',
        FORMAT ( 'Table'[Received Date], "YYYY-MM-DD" )
            = FORMAT ( 'Table'[First Itinerary Date], "YYYY-MM-DD" )
    )
)

FILTER function creates row context and thus you get access to columns. 
Other example is using X-iterators 

Measure2 =
SUMX (
    'Table',
    IF (
        FORMAT ( 'Table'[Received Date], "YYYY-MM-DD" )
            = FORMAT ( 'Table'[First Itinerary Date], "YYYY-MM-DD" ),
        'Table'[Column]
    )
)

Or more efficiently

Measure2 =
SUMX (
    'Table',
    (
        FORMAT ( 'Table'[Received Date], "YYYY-MM-DD" )
            = FORMAT ( 'Table'[First Itinerary Date], "YYYY-MM-DD" )
    ) * 'Table'[Column]
)

Hi @tamerj1 

 

Thankyou! I'm trying to create a column which calculates email response times. The issue is if they are outside of business hours the response time will calculate the total time between. So I need the column to check if the response times were on he same day and then if they weren't calculate the time between based on business hours between those two days. This is what I've got so far. 

SameDay = IF(FORMAT([Received Date], "YYYY-MM-DD") = FORMAT([First Itinerary Date], "YYYY-MM-DD"),

    TRUE,

    FALSE

)

 

 

BusinessHoursStart = TIME(9, 0, 0)  // 9:00 AM

BusinessHoursEnd = TIME(17, 0, 0)   // 5:00 PM

 

 

 

ResponseTime =

VAR StartTime = IF(

    HOUR([Received Date]) < 9,

    BusinessHoursStart,

    IF(HOUR([Received Date]) > 17, BusinessHoursEnd, [Received Date])

)

VAR EndTime = IF(

    HOUR([First Itinerary Date]) < 9,

    BusinessHoursStart,

    IF(HOUR([First Itinerary Date]) > 17, BusinessHoursEnd, [First Itinerary Date])

)

RETURN

IF(

    [SameDay],

    DATEDIFF(StartTime, EndTime, MINUTE),

    DATEDIFF(StartTime, BusinessHoursEnd, MINUTE) + DATEDIFF(BusinessHoursStart, EndTime, MINUTE)

)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.