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
Anonymous
Not applicable

Condition to return text value

Hello!

 

I have the following tables:

 

Tab 1: Dayparts

Daypart               Slot Start    Slot End

Early morning       07:00          09:59

Morning               10:00          12:59

......

 

Tab 2: Programmes

Programme          Slot mid point              Daypart

News                          11:35                    {DAX formula}

 

What I want to is to get a new column in the Programmes table that returns the value in Daypart if the Slot Mid Point falls between Slot Start and Slot End.

 

I would use Calculate if Daypart contained numbers, but what formula do I need to use so that I can get the right value from Dayparts/Daypart using the time conditions?

 

Any help much appreciated!

 

Many thanks,

 

George.

2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

Hi George,

 

Have a look at Static Segmentation on DAX Patterns:

http://www.daxpatterns.com/static-segmentation/

 

As long as your times have Data Type Time, you should be able to use this approach.

 

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

Hi George@Anonymous

 

Just making sure - you should use the VALUES function (not the VALUE function) in that pattern.

 

VALUES ( Dayparts[Daypart] ) is used to return a single value from the Dayparts[Daypart] column corresponding to each row of Programmes.

 

(The VALUE function is used to convert text to numbers).

 

The Dayparts table should not be related to Programmes for Static Segmentation.

 

Here is a dummy pbix file illustrating how you could create a Static Segmentation calculated column using the tables in your example.

https://www.dropbox.com/s/ike0q13pxhr3oca/Static%20segmentation%20time.pbix?dl=1

 

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

6 REPLIES 6
BhaveshPatel
Community Champion
Community Champion

Hi There,

 

You need to create a index column at the query stage in both the tables starting from 1.

 

Create a relationships between the tables based on this column.

 

and then

1. Create a Calculated column in Table 2

Slot Ending = IF(Table2[Slot Mid Point]<RELATED(Table1[Slot End]),"True","False")

2. Create another calculated column in Table 2

DayPart = IF(Table2[Slot Ending]="False","NA",RELATED(Table1[Daypart])).

 

This will give you the results expected.

 

Please refer to the screenshots for more information.

 

scr1.PNGscr2.PNGscr3.PNG

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.
OwenAuger
Super User
Super User

Hi George,

 

Have a look at Static Segmentation on DAX Patterns:

http://www.daxpatterns.com/static-segmentation/

 

As long as your times have Data Type Time, you should be able to use this approach.

 

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

Hi Owen,

 

Thank you for your response.

 

I had tried this but the problem I'm facing is that DAX will not allow me to draw the Daypart value from the Dayparts table (when I type in the Programmes Tab 

Daypart =  Calculate (Value(

 

it doesn't give me the option to pick 'Dayparts'[Daypart], nor does Related work after Value(. 

NB I have linked the two tables on Slot Start -> Slot Mid Point.

 

Any suggestions on how DAX can pick up the column from Dayparts?

 

Many thanks,

 

George. 

Hi George@Anonymous

 

Just making sure - you should use the VALUES function (not the VALUE function) in that pattern.

 

VALUES ( Dayparts[Daypart] ) is used to return a single value from the Dayparts[Daypart] column corresponding to each row of Programmes.

 

(The VALUE function is used to convert text to numbers).

 

The Dayparts table should not be related to Programmes for Static Segmentation.

 

Here is a dummy pbix file illustrating how you could create a Static Segmentation calculated column using the tables in your example.

https://www.dropbox.com/s/ike0q13pxhr3oca/Static%20segmentation%20time.pbix?dl=1

 

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

 Hi @OwenAuger

 

I am in urgernt need and request your help in following scenario

 

I have a mapping of Cluster and LOCs and want to display LOCs in a PBI Matrix object with different KPIs for the filtered Cluster in slicer.

 

Cluster1   LOC1

Cluster1   LOC2

Cluster1   LOC3

Cluster1   LOC4

 

Cluster2   LOC1

Cluster2   LOC2

 

Cluster3   LOC3

Cluster3   LOC4

 

My requirement is if no Cluster is filtered in slicer then it should show the list of LOCs for "Cluster1" only

Anonymous
Not applicable

Thanks a million for all your help! This did the trick.

 

I also had to fix the time format in the Advanced Editor to "time" rather than "datetime", which caused the two columns not to match.

 

George.

Helpful resources

Announcements
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.