Dax Function: SECOND
Category: Date and Time Functions
The SECOND function in Power BI extracts the second component from a given datetime value and returns it as an integer between 0 and 59.
Purpose
To isolate the seconds from a datetime value for precise time-based analysis or calculations.
Type of Calculations
Time extraction and dissection at the second level.
Practical Use Cases
- Analyzing timestamps in log files.
- Identifying patterns or events occurring at specific seconds.
- Supporting time-sensitive calculations in dashboards.
SECOND()
Parameter | Type | Description |
---|---|---|
datetime | Datetime | A single date, time, or datetime value (scalar or column). |
How Does SECOND Dax Function Works
The SECOND function works by extracting the seconds component from the
datetime
input. It breaks down the datetime value into its constituent parts (hour, minute, second) and isolates the seconds. Internally, it uses modular arithmetic to derive the seconds from a full datetime value.For example:
SECOND("2025-02-10 14:23:45")
→ Returns 45
.
What Does It Return?
- Type: Integer.
- Meaning: Returns the second (0–59) from the provided datetime value.
When Should We Use It?
- Extracting precise seconds for timestamp analysis.
- Aggregating or grouping data by specific second intervals.
- Debugging time-sensitive processes like transactions or system logs.
- Calculating differences between two datetime values at the second level.
Examples
Basic Usage
Extract seconds from a specific datetime:
SecondValue = SECOND(TIME(12, 15, 30))
Output: 30
.
Column Usage:
Apply the function to a column of datetime values:
SecondsColumn = SECOND(Table[Timestamp])
Output: Returns the second for each row in the Timestamp
column.
Advanced Usage
Combine with the TIMEVALUE function to handle time strings:
SecondFromTimeString = SECOND(TIMEVALUE("12:45:33"))
Output: 33
.
Tips and Tricks
- Datetime Format: Ensure the input is a valid datetime or time value; otherwise, the function will return an error.
- Combine with DateTime Functions: Use alongside functions like HOUR, MINUTE, or NOW for comprehensive time dissection.
- Time-Only Input: If analyzing time-only fields, ensure these fields are stored as time values or strings convertible by TIMEVALUE.
Potential Pitfalls
- Invalid Input: Passing non-datetime values will result in errors.
- Time Zones: Be cautious when working with datetime values involving multiple time zones.
- Large Datasets: Applying this function to large datasets can affect performance; consider calculated measures instead of columns when possible.
Performance Impact of SECOND DAX Function:
- Calculated columns using the SECOND function can impact model size for large datasets. Use measures where possible for improved performance.
- Optimize by ensuring datetime fields are indexed in the data source.
Related Functions You Might Need
- HOUR: Extracts the hour component.
- MINUTE: Extracts the minute component.
- NOW: Retrieves the current datetime value.
- TIME: Constructs a time value from individual hour, minute, and second components.
- TIMEVALUE: Converts a text string to a time value.
Want to Learn More?
For more information, check out the official Microsoft documentation for SECOND You can also experiment with this function in your Power BI reports to explore its capabilities.
Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.
It extracts the second component (0–59) from a datetime value.
Yes, the function works on a column of datetime values, returning the second for each row.
The function will return an error. Ensure inputs are valid datetime or time values.
Use the DATEDIFF function with SECOND
as the interval:
DATEDIFF(StartDate, EndDate, SECOND)
No, as long as the input is a valid datetime, the format does not affect the result.
Established in 2020, Lets Viz Technologies provides a full range of high-quality data analysis and data visualization services. We are also an authorized Zoho Partner.
Sitelinks