Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
android1
Post Patron
Post Patron

Using a slicer to change values in a column

Hi,

 

I have a calculated column which returns the number of times someone was on time for an appointment ->

 

On Time =
CALCULATE(COUNTROWS ( FILTER ( OTIF, OTIF[ShiftInTime] = OTIF[TimeFrom]
)))

 

I want to know how many times someone was 5/10/15/20/30 mins either side of appointment time. [TimeFrom] is

the appointment time, [ShiftInTime] is the time the person was there.

 

I have manually added a new table OT% with a column containing values for the slicer.

 

I have a measure targetperc OT = LASTNONBLANK('OT %'[OT %],1) and have applied it to above calculated column to give me -> On Time =
CALCULATE(COUNTROWS ( FILTER ( OTIF, OTIF[ShiftInTime] = OTIF[TimeFrom]*[targetperc OT]
)))

 

How do I determine if for example [TimeFrom] is 14:00  [ShiftInTime] is 14:05. In this case the person is within 5 mins. 13:55 would also be within 5 mins.

 

 

 

.TimeWithin.jpg

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi android1,

 

Based on my understanding, you want to get the ‘on time’ records which equal or less than the choice data in slicer, right?

 

You could follow below steps:

  1. Create a test table.

 Capture.PNG

  1. Add a calculate column to get the datediff of ‘ShiftInTime’ and ’TimeFrom’ column.

Dax: Range = ABS((HOUR([TimeFrom])*60 + MINUTE([TimeFrom]))-(HOUR([ShiftInTime])*60+MINUTE([ShiftInTime])))

Capture2.PNG

 

  1. Add a calculate column to get the within range.

Dax:

WithIn = if([Range]<=5,5,

IF([Range]<=10,10,

if([Range]<=15,15,

IF([Range]<=20,20,

if([Range]<=25,25,

IF([Range]<=30,30,

IF([Range]<=35,35,

if([Range]<=40,40,

IF([Range]<=45,45,50)))))))))

 Capture3.PNG

 

  1. Add a measure to calculate the count of specify rows.

Dax: On time = CALCULATE(COUNT('Out Time Record'[Range]), Filter (ALL( 'Out Time Record'), COUNTX(FILTER( 'Out Time Record', 'Out Time Record'[WithIn] >= Earlier ('Out Time Record'[WithIn] ) ),'Out Time Record'[Range])))

 

  1. Create the reports.

Slicer:

 Capture5.PNG

Table:

 Capture6.PNG

Card:

Capture7.PNG

Result:

Capture4.PNG

Notice: I drag the within to the slicer, the table displayed the current rows, the card view show the count of match records.

 

If above is not help, please provide more detail info and feel free to let me know.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi,

 

Yeah, that's what I'm looking for. What I need to also show is a count of appointments in these ranges when i put the measure into my table.

 

In pic below, I need to show 123K split by Region

 

 

OTIF.jpg

 

 

 

Greg_Deckler
Super User
Super User

I don't know the data types of your columns, but what I imagin you would do would be to get [Time From] and [ShiftInTime] to numeric values so that 14:00 becomes 1400. Then you could create a column like:

 

MinutesOffAbs = ABS([NumTimeFrom] - [NumShfitInTime]

Then you could normalize this with a big ugly IF statement like:

 

MinutsOffAbsNorm = IF([MinutesOffAbs]<5,0,IF([MinutesOffAbs]<10,5,10))

Obviously, add in all the extra nested IF's as necessary. Then, use this column in your slicer.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi smoupre,

 

Having trouble making that ugly IF statement. How do I continue it on

?

MinutsOffAbsNorm = IF([MinutesOffAbs]<5,0,IF([MinutesOffAbs]<10,5,10))

 

Trying 

MinutsOffAbsNorm = IF([MinutesOffAbs]<5,0,IF([MinutesOffAbs]<10,5,10,IF([MinutesOFFAbs] <15, 10,15)))

but getting error. Can I keep adding like this?

 

Hi android1,

>>but getting error. Can I keep adding like this?

You can refer to below formalu:

if(logic, value if true, if(logic, value if true,  if(logic, value if true, value if false) )

 

My previous reply

 

WithIn = if([Range]<=5,5,

IF([Range]<=10,10,

if([Range]<=15,15,

IF([Range]<=20,20,

if([Range]<=25,25,

IF([Range]<=30,30,

IF([Range]<=35,35,

if([Range]<=40,40,

IF([Range]<=45,45,50)))))))))

 

 

Reference:

IF Function (DAX)

 

Regards,

Xiao xin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.