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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
mrbuttons07
Helper II
Helper II

Calculated Measure for Time Column

Hello everyone,

I have a column that contains Transaction Times.

mrbuttons07_0-1723468237037.png

How do I create a calculated column that differentiates the time into different categories like below.

If Time is within 23:45:01.0000000 to 06:45:00.0000000, then it's Night.
If Time is within 06:45:01.0000000 to 15:15:00.0000000 then it's Morning.
If Time is within 15:15:01.0000000 to 23:45:00.0000000 then it's Noon.

Thanks!

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @mrbuttons07 - create a below calculated column , replace your table name and time column

Time Category =
SWITCH(
    TRUE(),
    'Date'[Transaction Time] >= TIME(23, 45, 1) || 'Date'[Transaction Time] <= TIME(6, 45, 0), "Night",
    'Date'[Transaction Time] >= TIME(6, 45, 1) && 'Date'[Transaction Time] <= TIME(15, 15, 0), "Morning",
    'Date'[Transaction Time] >= TIME(15, 15, 1) && 'Date'[Transaction Time] <= TIME(23, 45, 0), "Noon",
    BLANK()
)
 
Hope it helps




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
DatawithDinesh
Resolver II
Resolver II

You can create a calculated column that uses switch statement to specify the period of the day depending on the condition that you specify. See below code.

TimeCategory = 
VAR CurrentTime = [TransactionTime]
RETURN 
SWITCH(
    TRUE(),
    CurrentTime >= TIME(23, 45, 1) || CurrentTime < TIME(6, 45, 0), "Night",
    CurrentTime >= TIME(6, 45, 1) && CurrentTime < TIME(15, 15, 0), "Morning",
    CurrentTime >= TIME(15, 15, 1) && CurrentTime < TIME(23, 45, 0), "Noon",
    "Unknown"
)

Hope this helps!

rajendraongole1
Super User
Super User

Hi @mrbuttons07 - create a below calculated column , replace your table name and time column

Time Category =
SWITCH(
    TRUE(),
    'Date'[Transaction Time] >= TIME(23, 45, 1) || 'Date'[Transaction Time] <= TIME(6, 45, 0), "Night",
    'Date'[Transaction Time] >= TIME(6, 45, 1) && 'Date'[Transaction Time] <= TIME(15, 15, 0), "Morning",
    'Date'[Transaction Time] >= TIME(15, 15, 1) && 'Date'[Transaction Time] <= TIME(23, 45, 0), "Noon",
    BLANK()
)
 
Hope it helps




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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