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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jeffrock
Helper I
Helper I

creating a column by merging from 2 different column with a condition

Hi,

I have a requirement where I need to get the hours based on a single id for a particular day. so I have used LIST to break each id and expanded the LIST to rows which will give me the sequence of dates. My END objective is to get the required hours to get the TREND. in short, I need to create a column with Calc_date which will append time from the "start_date" column of 1st row of an ID from the start_date and time from the "End_Date" column to the last row of an ID. The middle rows will be 00:00:00.

if anyone Understood the situation, please help me out to get the solution as far as can.

 

IDStart_dateEnd_dateCalc_dateREQUIRED COLUMN DATE& TIMEREQUIRED COLUMN Hours
abc06/06/2020 01:3709/06/2020 18:0006/06/202006/07/2020 01:3722.5
abc06/06/2020 01:3709/06/2020 18:0007/06/202007/06/2020 00:0024
abc06/06/2020 01:3709/06/2020 18:0008/06/202008/06/2020 00:0024
abc06/06/2020 01:3709/06/2020 18:0009/06/202009/06/2020 18:0018
xyz10/10/2022 15:3013/10/2022 03:0010/10/202010/10/2022 15:308.5
xyz10/10/2022 15:3013/10/2022 03:0011/10/202011/10/2020 00:0024
xyz10/10/2022 15:3013/10/2022 03:0012/10/202012/10/2020 00:0024
xyz10/10/2022 15:3013/10/2022 03:0013/10/202013/10/2022 03:003

Thank you

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

Hi @jeffrock ,

According to your description, here's my solution. Create two calculated columns.

StartTime =
SWITCH (
    'Table'[Date_line],
    'Table'[Date Start], 'Table'[Date Start] + 'Table'[Time In],
    'Table'[Date_line]
)
EndTime =
SWITCH (
    'Table'[Date_line],
    'Table'[Date End], 'Table'[Date End] + 'Table'[Time Out],
    'Table'[Date_line]
)
    + TIME ( 23, 59, 59 )

Get the correct result.

vkalyjmsft_0-1663059623173.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

7 REPLIES 7
v-yanjiang-msft
Community Support
Community Support

Hi @jeffrock ,

According to your description, here's my solution. Create two calculated columns.

StartTime =
SWITCH (
    'Table'[Date_line],
    'Table'[Date Start], 'Table'[Date Start] + 'Table'[Time In],
    'Table'[Date_line]
)
EndTime =
SWITCH (
    'Table'[Date_line],
    'Table'[Date End], 'Table'[Date End] + 'Table'[Time Out],
    'Table'[Date_line]
)
    + TIME ( 23, 59, 59 )

Get the correct result.

vkalyjmsft_0-1663059623173.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hey @v-yanjiang-msft , Thank you for the Solution.

Is there any way in Dax where we can create a calculated column to convert a column from time format (eg: Time IN Column from above Table) to int

eg: if a column has 18:30:00 in time format it should return 18.3 or 18.5 in int format.

appreciate your Help

Thanks again

Hi @jeffrock ,

Use this formula:

Column = HOUR('Table'[Column1])&"."&MINUTE('Table'[Column1])

vkalyjmsft_0-1663148529919.png

Best Regards,
Community Support Team _ kalyj

Greg_Deckler
Community Champion
Community Champion

@jeffrock Add an Index column in Power Query for starters, otherwise there is no way to tell which row is 1st.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi, @Greg_Deckler I have added but am not sure how to fill the data based on condition. I m attaching the below data, please suggest to me the approach

 

IDDateSTartDate EndTime INTime OutDate_lineIndexStartTimeEnd Time
abc01/09/202205/09/202218:0015:0001/09/2022101/09/2022 18:0001/09/2022 23:59
abc01/09/202205/09/202218:0015:0002/09/2022202/09/2022 00:0002/09/2022 23:59
abc01/09/202205/09/202218:0015:0003/09/2022303/09/2022 00:0003/09/2022 23:59
abc01/09/202205/09/202218:0015:0004/09/2022404/09/2022 00:0004/09/2022 23:59
abc01/09/202205/09/202218:0015:0005/09/2022505/09/2022 00:0005/09/2022 15:00
xyz05/09/202208/09/202215:0020:0005/09/2022605/09/2022 15:0005/09/2022 23:59
xyz05/09/202208/09/202215:0020:0006/09/2022706/09/2022 00:0006/09/2022 23:59
xyz05/09/202208/09/202215:0020:0007/09/2022807/09/2022 00:0007/09/2022 23:59
xyz05/09/202208/09/202215:0020:0008/09/2022908/09/2022 00:0008/09/2022 20:00

 

Thank you

 

jeffrock_0-1662708977132.png

Hi, @Greg_Deckler,

please refer above 

need to create StartTime & End Time column

@jeffrock So I am still not 100% sure what the final result is supposed to be. But to get the first or last of something like what you have, you can basically use the technique used in MTBF.

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN

 

You'll have to adjust this obviously but for the start time, you want the MINX of the date based on certain conditions. Once you have that, compare to what is in the current row and if it is the same, return it, otherwise blank. For the end time, you want the MAXX.
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.