Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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.

 

 

  • AilleryO's avatar
    AilleryO
    3 years ago

    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 table
    RETURN
    CALCULATE( 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

  • Anonymous's avatar
    Anonymous
    Not applicable

    any one ?? :((

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi thx for answer screan from data look like that. 

       

       

  • AilleryO's avatar
    AilleryO
    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 ?

     

    • Anonymous's avatar
      Anonymous
      Not applicable

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

      • AilleryO's avatar
        AilleryO
        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