cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate I
Advocate I

Collection: Outcome values 0

I want to execute a DateDiff function in a collection. The calculation is also successful, but I don't succeed in displaying it correctly in a DataTable or Gallery. Although the correct value (e.g. 5) is displayed in the code, a 0 is displayed in the gallery.

 

Patch(
    CollectionName;
    Last(CollectionName);
    {
        Hours: DateDiff(
            Last(CollectionName).Start;
            Last(CollectionName).End;
            Hours
        )
    }
)

In the meantime I have tried out some possibilities and even deleted the collection and completely rebuilt it, but I just don't know where the problem is. Maybe someone has an idea and can help me.

1 ACCEPTED SOLUTION

Accepted Solutions

@brimstone 

Very nice screenshot, thank you! 

 

Your goal is to calculate the hours between ArbeitsBeginn and ArbeitsEnde.  The problem is you are changing the value of ArbeitsEnde in the same PATCH as when StundenNetto is calculated.  ArbietsEnds does not update until the entire PATCH is completed.  Because of this StundenNetto will be the result of DateDiff(18.10.2019 13:39,18.10.2019 13:39,Hours)

 

The solution is to PATCH twice instead: first update ArbeitsEnde and then update StundenNetto 

 

Patch(
    ArbeitszeitErfassung;
    Last(ArbeitszeitErfassung);
    {ArbeitsEnde: DateAdd(Now();5;Hours)}
);
Patch(
    ArbeitszeitErfassung;
    Last(ArbeitszeitErfassung);
    {
        StundenNetto: DateDiff(
            Last(ArbeitszeitErfassung).ArbeitsBeginn;
            Last(ArbeitszeitErfassung).ArbeitsEnde;
            Hours
        )
    }
);

 

Please make sure to double-check my snytax for the placement of brackets and semi-colons Cat Wink

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

8 REPLIES 8
Super User III
Super User III

@brimstone 

Can you please post some screenshots of the successful outcome (e.g. showing 5) and the unsuccessful outcome (e.g. showing 0)?  This will help my understanding of your issue.

 

It would also be helpful to see your inputs (e.g. last row of collection in the viewer)

@mdevaney 

I have set End to be 5 hours in the future (and thus the result of the DateDiff function is 5). In the Gallery the result should be in the column "Stunden", where currently 0 is displayed.


 


@brimstone 

Very nice screenshot, thank you! 

 

Your goal is to calculate the hours between ArbeitsBeginn and ArbeitsEnde.  The problem is you are changing the value of ArbeitsEnde in the same PATCH as when StundenNetto is calculated.  ArbietsEnds does not update until the entire PATCH is completed.  Because of this StundenNetto will be the result of DateDiff(18.10.2019 13:39,18.10.2019 13:39,Hours)

 

The solution is to PATCH twice instead: first update ArbeitsEnde and then update StundenNetto 

 

Patch(
    ArbeitszeitErfassung;
    Last(ArbeitszeitErfassung);
    {ArbeitsEnde: DateAdd(Now();5;Hours)}
);
Patch(
    ArbeitszeitErfassung;
    Last(ArbeitszeitErfassung);
    {
        StundenNetto: DateDiff(
            Last(ArbeitszeitErfassung).ArbeitsBeginn;
            Last(ArbeitszeitErfassung).ArbeitsEnde;
            Hours
        )
    }
);

 

Please make sure to double-check my snytax for the placement of brackets and semi-colons Cat Wink

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

 @mdevaney 

This works perfectly, thank you very much!

@brimstone 

No problem at all.  By the way, what language is that collection using?  I only speak English so I was not able to understand it fully.

@mdevaney 

 

It's german 🙂 

@brimstone 

I was hoping it was German!  My ancestry is part German and I think it would be pretty neat to learn the language some day.

@mdevaney 

I can fully understand your drive to learn German because of that.

I get to hear more often that the language isn't very easy to learn, but I wish you a lot of fun learning it!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (4,756)