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
ItalianScallion
Frequent Visitor

Night time vs day time

Hello,

I have 2 tables, FactTransaction with column TIME_TPA which is a reading time and the other Sunset_Sunrise_TPA with SUNSET SUNRISE column.
I need a new column that checks weather or not the READINGTIME is at night or during the day.

I tried with an this formula but it shows 4pm as night and 12am as day. 

DayCheck = IF(AND(vw_FactTransaction_Hourly[Time_TPA]>= RELATED(Sunset_Sunrise_TPA[Sunrise]), vw_FactTransaction_Hourly[Time_TPA] <= RELATED(Sunset_Sunrise_TPA[Sunset])),"Daytime","Night")
 
How can I compare these two times so that if TIME_TPA is after SUNSET and before SUNRISE it's nighttime?
Thanks
 
 
EDIT:
Also tried 
DayCheck = IF(AND(TIME(HOUR(vw_FactTransaction_Hourly[Time_TPA]),MINUTE(vw_FactTransaction_Hourly[Time_TPA]),0)>= TIME(HOUR(RELATED(Sunset_Sunrise_TPA[Sunrise])),MINUTE(RELATED(Sunset_Sunrise_TPA[Sunrise])),0), TIME(HOUR(vw_FactTransaction_Hourly[Time_TPA]),MINUTE(vw_FactTransaction_Hourly[Time_TPA]),0) <= TIME(HOUR(RELATED(Sunset_Sunrise_TPA[Sunset])),MINUTE(RELATED(Sunset_Sunrise_TPA[Sunset])),0)),"Daytime","Nighttime")
In an attempt to make it into a time function, no luck, everything but midnight comes out as nighttime lol 
Halp plz
 
1 REPLY 1
v-rongtiep-msft
Community Support
Community Support

Hi @ItalianScallion ,

I have some doubt. Each row in vw_FactTransaction_Hourly[Time_TPA] compare to with each row in Sunset_Sunrise_TPA[Sunset]? If in row 1, there is 05:00:00 in vw_FactTransaction_Hourly[Time_TPA] and 23:00:00 in Sunset_Sunrise_TPA[Sunset], What would it output?  The result is "Night"? Could you please provide more details?

 

How to compare daytime and night?

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

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.

Top Solution Authors