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

Calculated column not returning what I'm expecting

I am trying to determine from another column if their join time was in the morning or in afternoon. If a join time is AM and leave time is PM, then I want the calculated column to show "AM/PM"
The table context is each row is a record of a person joining a training.
The reason I want to do this is I want to determine how many distinct people were in the morning call and how many people were in the afternoon call.
So if a person joined in the morning and left in the afternoon, it means they were in both AM and PM sessions.

I wrote the following calculated column:

AM/PM Session =
SWITCH(
true(),
AND(CONTAINS('Activity Table','Activity Table'[Join Time], "AM"), CONTAINS('Activity Table','Activity Table'[Leave Time], "PM")), "AM/PM",
AND(CONTAINS('Activity Table','Activity Table'[Join Time], "AM"), CONTAINS('Activity Table','Activity Table'[Leave Time], "AM")), "AM",
AND(CONTAINS('Activity Table', 'Activity Table'[Join Time], "PM"), CONTAINS('Activity Table','Activity Table'[Leave Time], "PM")), "PM",
"N/A"
)

Join and leave time I made both of them text values, and the calculated columns are bringing back "N/A". What am I missing here?
1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @JawnPBI 
Try to modify your formula to :

AM/PM Session Switch =
SWITCH(TRUE(),
    CONTAINSSTRING('Activity table'[Join Time], "AM") && CONTAINSSTRING('Activity table'[Leave Time], "PM"), "AM/PM",
    CONTAINSSTRING('Activity table'[Join Time], "AM"), "AM",
    CONTAINSSTRING('Activity table'[Join Time], "PM"), "PM",
    "N/A"
)
Ritaf1983_0-1686274074166.png

 


You don't have to have your data in text format it works perfectly with time format too.

Ritaf1983_1-1686273778842.png

Link to the sample file 

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



View solution in original post

4 REPLIES 4
JawnPBI
Frequent Visitor

That works!! Thank you 🙂

 

Glad to help☺️

Ritaf1983
Super User
Super User

Hi @JawnPBI 
Try to modify your formula to :

AM/PM Session Switch =
SWITCH(TRUE(),
    CONTAINSSTRING('Activity table'[Join Time], "AM") && CONTAINSSTRING('Activity table'[Leave Time], "PM"), "AM/PM",
    CONTAINSSTRING('Activity table'[Join Time], "AM"), "AM",
    CONTAINSSTRING('Activity table'[Join Time], "PM"), "PM",
    "N/A"
)
Ritaf1983_0-1686274074166.png

 


You don't have to have your data in text format it works perfectly with time format too.

Ritaf1983_1-1686273778842.png

Link to the sample file 

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



vicky_
Super User
Super User

I think you just need to swap out the CONTAINS function for the CONTAINSSTRING function. https://learn.microsoft.com/en-us/dax/containsstring-function-dax

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.