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

If command with new measure and column in table

Hi All,

 

I'm quite new to Power BI and have a question regarding the if command. 

 

I created a new measure with DATEDIFF and called this 'difference time'. Right now, I want to use a new measure that will measure when the ''difference time'' is bigger than ''appointment.type,duration'' which is a column in my table.

 

I tried to do this with the following command:

Uitloop = IF('studenten'[difference time] > 'studenten'[appointment.type.duration], "yes", "no")

However, it doesn't recognize the appointment type duration (see the attached screenshot).

 

Any help will be appreciated! Thank you in advance!

 

ninawassenaar_1-1639484983131.png

 

 

ninawassenaar_0-1639484965089.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Here you want to compare [Difference time] measure which is in Whole number type with [Appointment.type.duration] column which is in Time type. So you will get error in your visual. You need to convert Time to whole number or convert whole number to Time by calculate and then compare them.

Here I convert [Difference time] to Time type and then compare them.

My Code.

 

Uitloop = 
VAR _HOUR =
    QUOTIENT ( [Difference time], 60 )
VAR _MINUTES =
    MOD ( [Difference time], 60 )
VAR _Difference_time =
    TIME ( _HOUR, _MINUTES, 00 )
RETURN
    IF (
        _Difference_time > MAX ( studenten[Appointment.type.duration] ),
        "Yes",
        "No"
    )

 

Result is as below.

1.png

You can download my attatch sample file to learn more details.

 

Best Regards,
Rico Zhou

 

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

9 REPLIES 9
Anonymous
Not applicable

Hi @VahidDM and @ValtteriN,

 

Thank you for the reply. It works when I use the Max or Sum aggregate, however, if I want to add the measure to my table to see which ones go over the predicted appointment type duration, it says it can't show the visual.

This happens when I use either Max or Sum, or any other aggregate. 

 

Thank you agian for your help!

 

ninawassenaar_0-1639487036303.pngninawassenaar_1-1639487056584.png

 

@Anonymous 

 

It because the type of your column is Text, change it to whole or decimal number.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

Sample data: 

 

Execution.start.timeExecution.end.timeAppointment.type.duration
10:31:0012:12:0000:35:00
10:48:0012:12:00

01:00:00

12:47:0013:56:0000:35:00
06:41:0007:48:00

00:40:00

12:17:0013:12:0001:00:00
11:38:0012:33:0000:40:00
07:45:0008:13:0000:35:00
08:44:0009:09:0000:35:00

 

First I found the difference in time between the execution start time and execution end time by using a measure:

Difference time = DATEDIFF(MIN(studenten[execution start time]),Max(studenten[execution end time]),MINUTE)
 
This gave me the following result:
Execution.start.timeExecution.end.timeAppointment.type.duration

Difference time

10:31:0012:12:0000:35:00101
10:48:0012:12:00

01:00:00

84

12:47:0013:56:0000:35:0069
06:41:0007:48:00

00:40:00

67

12:17:0013:12:0001:00:0055
11:38:0012:33:0000:40:0055
07:45:0008:13:0000:35:0028
08:44:0009:09:0000:35:0025
 
Now I want to find when the ''difference in time'' is bigger than the appointment.type.duration, when this is the case I want it to say ''yes'' if this is not the case I want it to say ''no''. In the example I have added it manually (in red), but actually want to use a formula to automatically get this. Which I tried to do with the IF command. 
 
Execution.start.timeExecution.end.timeAppointment.type.duration

Difference time

Uitloop

10:31:0012:12:0000:35:00101yes
10:48:0012:12:00

01:00:00

84

yes

12:47:0013:56:0000:35:0069yes
06:41:0007:48:00

00:40:00

67

yes

12:17:0013:12:0001:00:0055no
11:38:0012:33:0000:40:0055yes
07:45:0008:13:0000:35:0028no
08:44:0009:09:0000:35:0025no
Anonymous
Not applicable

If I do this, it changes everything to 0. 

 

Before it showed

Appointment.type.duration

00:40:00 --> meaning the predicted duration of the appointment is 40 minutes. When i change the type to a whole number it changes it to a 0. 

 

I'll try to post a sample dataset for you to take a look at! 

 

Thank you again so much for the help. 

Hi,

SUM doesn't work with text but MAX will return values anyway. Also instead of whole number you can use decimal number data type. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi,

 

If I try to change it to a decimal number it gives me an error, and the visual still doesn't work with Max.

 

ninawassenaar_0-1639491045241.png

 

 

Anonymous
Not applicable

Hi @Anonymous ,

Here you want to compare [Difference time] measure which is in Whole number type with [Appointment.type.duration] column which is in Time type. So you will get error in your visual. You need to convert Time to whole number or convert whole number to Time by calculate and then compare them.

Here I convert [Difference time] to Time type and then compare them.

My Code.

 

Uitloop = 
VAR _HOUR =
    QUOTIENT ( [Difference time], 60 )
VAR _MINUTES =
    MOD ( [Difference time], 60 )
VAR _Difference_time =
    TIME ( _HOUR, _MINUTES, 00 )
RETURN
    IF (
        _Difference_time > MAX ( studenten[Appointment.type.duration] ),
        "Yes",
        "No"
    )

 

Result is as below.

1.png

You can download my attatch sample file to learn more details.

 

Best Regards,
Rico Zhou

 

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

ValtteriN
Super User
Super User

Hi,

You can't directly compare measure and column between each other within a new measure. To solve this you can use functions like MAX or SELECTEDMEASURE to refrer to your column. E.g. IF([Difference time]>MAX('studenten'[appoinment type duration], "Yes","No")

I hope this helps to solve your issue and if it does consider accepting this post as a solution and giving it a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




VahidDM
Super User
Super User

Hi @Anonymous 

 

If you reference a column in a measure, you must wrap the column in an aggregation function like MIN, MAX, SUM, AVERAGE, etc.
So use this:

Uitloop = IF('studenten'[difference time] > sum('studenten'[appointment.type.duration]), "yes", "no")

 

or 
Uitloop = IF('studenten'[difference time] > sum('studenten'[appointment.type.duration]), "yes", "no")


If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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