cancel
Showing results for
Did you mean:

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Helper II

## Dax TIME restaurant transaction

I couldn't find a similar topic in the forum, so maybe someone can help me. I mean, I work in the restaurant sector. Document = Transactions, now we want to track the differences between account opening and closing times to see if employees are honest. The problem arises because it can not be calculated with a simple formula DateDIFF why?? because each receipt can have several items, as you know, you go to rest, you order many things, and for each item in the database there is a time which is then summed up and comes out stupid. Time DIFF measure is the stupid thing I came up with unfortunately 😞 As I calculated it is a simple formula in excel, the times are correct, however, I do not know how to build the measure so that it was counted correctly. I am adding screens so that you can see what data I have. Where it is " simple excel time formula" as you can see the values are reasonably correct but not. I will be much obliged for help how to solve this problem.

1 ACCEPTED SOLUTION
Memorable Member

Hi,

Using your data I made a pbix with 2 solutions :

1/ Using Power Query to group by DOCUMENT number and calculate duration in a calculated column. Very easy and quick. (see my Query Tickets Grouped)

2/ Using a mesure in DAX with a formula that looks like :

`Mesure In DAX Duration = VAR BeginTicket = MIN ( TableTickets[Open DOC HOUR] )VAR EndTicket = MAX( TableTickets[CLOSE DOC HOUR] )VAR CurrTicket = SELECTEDVALUE( TableTickets[DOCUMENT] )//means Take the document number on the row of the tableRETURNCALCULATE( EndTicket-BeginTicket , TableTickets[DOCUMENT]=CurrTicket )`

You can then use the format menu of the column to display it as you want or create your own format. Using n for minutes (m is for month), so FORMAT( [Duration], "nn" ) will give you a time in minutes with 2 digits.
You'll find attached my Excel files with your data and the pbix file with solution in DAX and in Power Query.
Let us know if it works
11 REPLIES 11
Memorable Member

Hi,

It would help if you could provide sample data as a table we can copy, or download, so we can play around your data and maybe understand your exact needs...
One calculation per order ? With min and max time ?

Helper II

I can't add file because "xlsx" and PBIX is nos supported i tget comment

Memorable Member

Add them in a zip file, or at least copy and paste data in a table in your message so we can copy and paste data as well from your message and not typed them in.

Thanks

Helper II

Memorable Member

Sorry I cannot do anything with an image, can you paste as a table not as an image.

Thanks

Helper II

As you can see, the table is not difficult, more or less the problem is that I need to know the "measure" to calculate the time between opening and closing the document, the problem is that there are sometimes many items to 1 document 😞

The point is to calculate exactly what is the time between opening and closing the document, but so that the time when there are more items does not add up, so that it is the real value of the delay.

Helper II
 DOCUMENT RESTAURANT EXEC DATE YEAR MONTH WEEK DAY TowNazwa GrupaAdm Open DOC HOUR CLOSE DOC HOUR PAR/389 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:16 06-01-23 18:20 PAR/389 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:16 06-01-23 18:20 PAR/393 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:31 06-01-23 18:35 PAR/393 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:31 06-01-23 18:35 PAR/402 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 19:11 06-01-23 19:13 PAR/391 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:21 06-01-23 18:30 PAR/391 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:21 06-01-23 18:30 PAR/396 Restauracja Focaccia 2023-01-06 2023 1 Friday HERBATA ROZGRZWAJĄCA CZARNA FOC NAPOJE GORĄCE 06-01-23 18:38 06-01-23 18:48
Memorable Member

Hi,

Using your data I made a pbix with 2 solutions :

1/ Using Power Query to group by DOCUMENT number and calculate duration in a calculated column. Very easy and quick. (see my Query Tickets Grouped)

2/ Using a mesure in DAX with a formula that looks like :

`Mesure In DAX Duration = VAR BeginTicket = MIN ( TableTickets[Open DOC HOUR] )VAR EndTicket = MAX( TableTickets[CLOSE DOC HOUR] )VAR CurrTicket = SELECTEDVALUE( TableTickets[DOCUMENT] )//means Take the document number on the row of the tableRETURNCALCULATE( EndTicket-BeginTicket , TableTickets[DOCUMENT]=CurrTicket )`

You can then use the format menu of the column to display it as you want or create your own format. Using n for minutes (m is for month), so FORMAT( [Duration], "nn" ) will give you a time in minutes with 2 digits.
You'll find attached my Excel files with your data and the pbix file with solution in DAX and in Power Query.
Let us know if it works
Community Support

Hi @Krzysiek87 ,

I'm a little confused about your needs, Could you please explain them further? It would be good to provide a screenshot of the results you are expecting and desensitized example data.

Thanks for your efforts & time in advance.

Best regards,
Community Support Team_Binbin Yu

Helper II

Hi thx for answer screan from data look like that.

Helper II

any one ?? :((