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.
I am looking to create a new column in my dataset that classifies time between 9am and 5pm into one bucket ( say "business hours") and 5pm to 8 am as "after hours". I have a [TIME] column on which this is based.
I am totally new to PowerBI and getting myself confused between the difference between when the DAX language is needed and when the M language is needed. I am doing this on the PowerBI desktop. Strange - I cant find any discussion about daypart manipulations ( maybe didnt look enough).
My query to create the column:
if ( [Time] >= "9:00:00 AM" and [Time] <= "5:00:00 PM" ) then "Business hours" else "After hours"
Getting "error" values in the new column created. Tried many iterations without success.
Solved! Go to Solution.
here is something i tried, i created hour column using DAX , hope it is helpful
Dax Expression
Hours = if(sample2[Time1] >= time(9,0,0) && sample2[Time1] <= time(17,0,0), "Business", "After")
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
The solution by parry2k works if you are using DAX to create the formula for the new column ( directly from the Report tab). But when trying to addd a new "custom column" from the query editor, looks like the M language is used there instead ( confusing!!). Here is the M langauge that worked for me there :
if [Time] >= Time.FromText("09:00:00") and [Time] <= Time.FromText("17:00:00") then "Business Hours" else "After Hours"
The comparable DAX formula from the Report tab is:
if ([Time] >= time(9,0,0) && [Time] <= time(17,0,0) ) , "Business hours" , "After hours")
The solution by parry2k works if you are using DAX to create the formula for the new column ( directly from the Report tab). But when trying to addd a new "custom column" from the query editor, looks like the M language is used there instead ( confusing!!). Here is the M langauge that worked for me there :
if [Time] >= Time.FromText("09:00:00") and [Time] <= Time.FromText("17:00:00") then "Business Hours" else "After Hours"
The comparable DAX formula from the Report tab is:
if ([Time] >= time(9,0,0) && [Time] <= time(17,0,0) ) , "Business hours" , "After hours")
here is something i tried, i created hour column using DAX , hope it is helpful
Dax Expression
Hours = if(sample2[Time1] >= time(9,0,0) && sample2[Time1] <= time(17,0,0), "Business", "After")
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
This worked for me only when I created the formula from the "Report " tab using the Dax editor there like you did in your exmaple. The same formula throws errors when doing so from the query editor ( via "edit queries" on ribbon)
Strange: I am using this ( modified from your code above) still not working. Getting a "token literal expected" error in the editor:
I have only one table so didint use the qualified table reference name. the error is on the "&&" part.
if([Time] >= time(9,0,0) && [Time] <= time(17,0,0), "Business", "After")
FYI I am doing this from the query editor screen and clicking on "custom column" under "add column" tab on the ribbon.
If i change it to below, the syntax error goes away but now new error : "Expression Error " The name 'time' wasnt recognized. Make sure its spelled correctly "!!
Notice "time' in lowercaps:
if [Time] >= time(9,0,0) and [Time] <= time(5,0,0) then "9am-5pm" else "6pm-8am"
I think following will work, may be some syntax issue but just to give you an idea, add a column and create following DAX:
if (Table[Time] >= time(9,0,0) && Table[Time] <= time(17,0,0) ) , "Business hours" , "After hours")
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |