# Assign value from previous variable

**URL:** <https://community.dhis2.org/t/assign-value-from-previous-variable/62803>\
**Category:** Implementation - Implémentation\
**Created:** [19 December 2024 16:36 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803 "2024-12-19T16:36:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![emad](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/emad/32/39614_2.png) [@emad](https://community.dhis2.org/u/emad)\
**Post date:** [19 December 2024 16:36 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/1 "2024-12-19T16:36:23Z")

</div>

hi everyone  
i did program rule :-  
the action is assign value to data element  
the variable source data element from previous event  
It works well if there is a difference of one day or more between events, but if two events occur on the same day, it does not take the value of the previous event on the same day, but rather takes the value of the event that precedes it by one day.

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [23 December 2024 14:52 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/2 "2024-12-23T14:52:43Z")

</div>

Hi @emad

Would you please share the program rule configuration so I could test this on [play.dhis2.org](http://play.dhis2.org)?

Thanks!

---

<div class="post-metadata">

**Author:** ![emad](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/emad/32/39614_2.png) [@emad](https://community.dhis2.org/u/emad)\
**Post date:** [23 December 2024 18:50 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/3 "2024-12-23T18:50:54Z")

</div>

![image](https://dhis2.b-cdn.net/uploads/default/original/3X/2/c/2c9617ab6cc3f811a73118bfab4fa44512e4b384.png)  
 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/8/3/83db9f9f76f0ccbab1608c48743937e946457bfa.png)  
 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/8/2/82ebba8308ebd39689c10e10f16ce06f4a2ac425.png)

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [24 December 2024 14:23 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/4 "2024-12-24T14:23:37Z")

</div>

Hi @emad

It appears that this issue might be because of the condition expression. Since this program rule action needs to run whenever there’s a new event, you might want to try an expression that will be revaluated when a new event is created. Would you like to test `V{event_count} != 1` for example?

Please test and tell me if it works. 🙏

Thanks!

---

<div class="post-metadata">

**Author:** ![emad](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/emad/32/39614_2.png) [@emad](https://community.dhis2.org/u/emad)\
**Post date:** [5 January 2025 06:59 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/5 "2025-01-05T06:59:08Z")

</div>

It didn’t work.

 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/1/f/1fce41dc0858bcfff162816937e9bf4deee5754b.png)  
 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/0/8/08a416d25f3091fbf0418d1220f4f706491972b8.png)  
 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/d/9/d9ab6d54ba5f0b356cf9e9f5c540174e863ff360.png)  
Note that the Stock on hand in the third event returned to 100.

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [10 February 2025 15:08 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/6 "2025-02-10T15:08:42Z")

</div>

Thanks for the screenshots @emad ! I will try to reproduce this on [play.dhis2.org](http://play.dhis2.org) in the Capture app so we can triage this to the [@dhis2-tracker](https://community.dhis2.org/groups/dhis2-tracker) team.

---

<div class="post-metadata">

**Author:** ![emad](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/emad/32/39614_2.png) [@emad](https://community.dhis2.org/u/emad)\
**Post date:** [8 June 2025 08:48 UTC](https://community.dhis2.org/t/assign-value-from-previous-variable/62803/7 "2025-06-08T08:48:48Z")

</div>

> [@Gassim](#):
>
> V{event\_count} != 1

Aid mubark bro  
i was very busy  
i try your recommendation but still the same issue
