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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Yasin_123
Regular Visitor

Calculate timedifference between slicer which contains 2 rows of data

Hello guys, 

 

I hope you all had a pleasent start into the new year 🙂

 

I have two problems in Power BI:

  1. I have a table containing the start- and enddate of a certain failure of a machine (see picture below). In a "between" slicer I want to be able to select the start and the end date of my observation period. But I don't know how to get them into one slicer. The picture below shows, that I am right now only able to put the start date or the end date of the malfunction into the "between" slicer. Do you guys know a solution concerning this problem?

Yasin_123_0-1705045020472.png

Yasin_123_1-1705045253881.png

 

2. If you guys know the answer to the first problem you may proceed to the next one. After getting the slicer with the two different dates I need to calculate the timedifference between those two dates which were put into the slicer.

E.g.: If my start date is the 1/15/2024 and my end date is 1/20/2024 the days between those dates are 5 (or 6 if you count the 15th too)

Do you guys know a solution to this? I need the time difference to use for further calculations.

 

I hope you can help me in this matter 🙂

 

Thank you for your hep in advance!

 

Kindly,

Yasin

 

 

1 ACCEPTED SOLUTION

Hi @Yasin_123 ,

 

We can create a date table as a slicer. Note that this date table does not have any modeling relationship with the other tables.

 

 

Date Table = CALENDAR(Date(2023,1,1),Date(2024,12,31))

 

We can create measures.

 

Flag = IF( MAX('Closed Orders Table'[Start of order]) >= MIN('Date Table'[Date]) && MAX('Closed Orders Table'[Start of order]) <= MAX('Date Table'[Date]),1,0)
Flag2 = IF( MAX('Open Orders Table'[Start of order]) >= MIN('Date Table'[Date]) && MAX('Open Orders Table'[Start of order]) <= MAX('Date Table'[Date]),1,0)
Flag3 = IF( MAX('Closed Tickets Table'[Start of malfunction]) >= MIN('Date Table'[Date]) && MAX('Closed Tickets Table'[Start of malfunction]) <= MAX('Date Table'[Date]),1,0)
Flag4 = IF( MAX('Open Tickets Table'[Start of malfunction]) >= MIN('Date Table'[Date]) && MAX('Open Tickets Table'[Start of malfunction]) <= MAX('Date Table'[Date]),1,0)

 

Place [Flag=1] on visual object screening .

 

If this doesn't help, give your expected results.

 

Best Regards,

Neeko Tang

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

8 REPLIES 8
v-tangjie-msft
Community Support
Community Support

Hi @Yasin_123 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.

vtangjiemsft_0-1705286992675.png

(2) We can create a date table.

Date Table = CALENDAR(FIRSTDATE('Table'[Start of malfunction]),LASTDATE('Table'[End of malfunction]))

(3) We can create measures. 

Flag = IF( MAX('Table'[Start of malfunction]) >= MIN('Date Table'[Date]) && MAX('Table'[End of malfunction]) <= MAX('Date Table'[Date]),1,0)
timedifference = DATEDIFF(MIN('Table'[Start of malfunction]),MAX('Table'[End of malfunction]),DAY)
timedifference for slicer = DATEDIFF(MIN('Date Table'[Date]),MAX('Date Table'[Date]),DAY)

(4) Place [Flag=1] on visual object screening and then the result is as follows.

vtangjiemsft_1-1705287235862.pngvtangjiemsft_2-1705287262366.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

(Virus scan in progress ...)

Hello @v-tangjie-msft and @lbendlin,

thank you for your quick response. To understand my problem better I provide you guys with some test data.

 

I want to calculate the MTTR (Mean Time to Repair), MDT (Mean Downtime) and MTBF (Mean Time Between Failure) for the machines (Equipment in data) of our company. 

MDT= SUM(Closed Ticket Date - Opened Ticket Date)/ Number of Tickets of the Machine in the observation period
MTTR= SUM (Closed Order Date - Opened Order Date)/Number of Orders of the Machine in the observation period
MTBF= (Observation Period-Failure time of Machine)/Number of Failures of the Machine in the observation period

When I am saying observation Period, I want to give a Startdate and a Enddate, via the slicer where all Tickets are considered in the calculation if their Start Date is over the slicer Start date and under the slicer Enddate.

Yasin_123_0-1705307989957.png

The difference in Time between start and end date should be used to calculate the obeservation period. With which I can then calculate my needed KPIs.
It could happen that I will add also the time but this I should be able to do by myself if you guys can tell me how to solve this problem. 

Anonymized Data for Help.pbix

Once the table should show me the KPI for the specified obeservation date and then also the dates per month (which should be easier).
Thanks for your help in advance!

Kindly,
Yasin

Hi @Yasin_123 ,

 

I don't have permission to open your link, please re-grant permission to link and share.

Update the measure.

 

Flag = IF( MAX('Table'[Start of malfunction]) >= MIN('observation Period Table'[Date]) && MAX('Table'[Start of malfunction]) <= MAX('observation Period Table'[Date]),1,0)

 

vtangjiemsft_1-1705391684986.png

 

Best Regards,

Neeko Tang

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

(Virus scan in progress ...)

Hello @v-tangjie-msft,

 

is there another way to share the data? Somehow my company won't give access to you via onedrive. And uploading data to the forum is only possible if you are from support or a super user. 
Best Regards,

 

Yasin

Hi @v-tangjie-msft,

 

as it is not possible to send you the data I will make pictures and tables: 
Modell is the following:

Yasin_123_1-1705394792214.png

All Tickets Table: 
Is merge of closed and opened Tickets and connected to other table via tickets

All Orders Table:
Is merge of closed an opened orders and connected to other table via orders
Date Table:

Normal Date Table with dates etc.

 

Closed Orders Table:

Start of orderEnd of orderOrder CodeTicket CodeEquipmentMachine FailureFailure Time
27.06.202322.07.2023100087400001No0
25.12.202328.12.2023100118400021Yes12
10.11.202318.12.2023100219400111Yes0
10.08.202320.08.20231003310400334No0
01.01.202301.01.20231003511400245Yes8
23.12.202329.12.2023100128400021Yes12
01.07.202315.07.2023100157400001No0

 

Open Orders Table:

Start of orderOrder CodeTicket CodeEquipmentMachine FailureFailure Time
01.03.2024100011400001No0
05.01.2024100022400022Yes5
10.01.2024100053400102No0
15.01.2024100074400304Yes10
03.01.2024100202400022Yes5

 

Closed Tickets Table:

Start of malfunctionEnd of malfunctionTicket CodeOrder CodeEquipmentMachine FailureFailure Time
25.06.202328.07.2023710008400001No0
22.12.202330.12.2023810011400021Yes12
10.11.202320.11.2023910021400111Yes0
08.08.202310.08.20231010033400334No0
01.01.202402.01.20241110035400245Yes8


Open Tickets Table:

Start of malfunction

Ticket CodeOrder CodeEquipmentMachine FailureFailure Time
01.01.2024110001400001No0
02.01.2024210002400022Yes5
10.01.2024310005400102No0
12.01.2024410007400304Yes10
15.01.2024510010400256Yes7

Hi @Yasin_123 ,

 

We can create a date table as a slicer. Note that this date table does not have any modeling relationship with the other tables.

 

 

Date Table = CALENDAR(Date(2023,1,1),Date(2024,12,31))

 

We can create measures.

 

Flag = IF( MAX('Closed Orders Table'[Start of order]) >= MIN('Date Table'[Date]) && MAX('Closed Orders Table'[Start of order]) <= MAX('Date Table'[Date]),1,0)
Flag2 = IF( MAX('Open Orders Table'[Start of order]) >= MIN('Date Table'[Date]) && MAX('Open Orders Table'[Start of order]) <= MAX('Date Table'[Date]),1,0)
Flag3 = IF( MAX('Closed Tickets Table'[Start of malfunction]) >= MIN('Date Table'[Date]) && MAX('Closed Tickets Table'[Start of malfunction]) <= MAX('Date Table'[Date]),1,0)
Flag4 = IF( MAX('Open Tickets Table'[Start of malfunction]) >= MIN('Date Table'[Date]) && MAX('Open Tickets Table'[Start of malfunction]) <= MAX('Date Table'[Date]),1,0)

 

Place [Flag=1] on visual object screening .

 

If this doesn't help, give your expected results.

 

Best Regards,

Neeko Tang

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

lbendlin
Super User
Super User

It is as easy as using VALUES(<slicer date column>)  as your filter.  Or if you really need to know the range, use MIN and MAX against that slicer date column.

Helpful resources

Announcements