# Date Difference between aggregated and non aggregated field

**URL:** <https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881>\
**Category:** Q&A\
**Tags:** date, calculations, Business-Intelligence-Engineer, quick-sight\
**Created:** [June 4, 2024, 10:04am UTC](https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881 "2024-06-04T10:04:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarveyB-B](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@HarveyB-B](https://community.amazonquick.com/u/HarveyB-B)\
**Post date:** [June 4, 2024, 10:04am UTC](https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881/1 "2024-06-04T10:04:33Z")

</div>

I have read through a couple posts relating to this, but found no solution for myself. It may be the way i am writing my calculated fields though.

For context, i am creating a report on arrears and payments  
This is one of the calculated fields i am using which is an accounting period date. This is basically the date for the end of each month, based on an accounting period. This means that i can group the fields monthly.

> [@Turning an integer value into a date field](https://community.amazonquick.com/t/turning-an-integer-value-into-a-date-field/30563/11):
>
> Breakdown of the solution: Max date for each accountingperiod I then formatted this as an actual date (concat to include ‘/’ between YYYY/MM/DD) [image] I then parsed this field as a date: [image] [image]

This is the other fields i am using:  
IntoArrears - returns when a PAYMENT enters arrears

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/9/4/94f9eb296ca08621d31691f7f2742e3f93da81e3.png)

MinArrearsDate - returns when a case enters arrears  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/9/f/9f813425ac1c650c4f25d293c4f616f4a3d8450f.png)

I want to create a calculated field which is if we are in the current AccountingPeriodDate, do a date difference between MinArrearsDate and now(), if we aren’t in the current AccountingPeriodDate, do a date difference between MinArrearsDate and AccountingPeriodDate. What this should do is return the days in arrears as of end of each month, but if we are in the current month, it should return the current days in arrears.

How can i achieve this?

---

<div class="post-metadata">

**Author:** ![David\_Wong](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/david_wong/32/15630_2.png) [@David\_Wong](https://community.amazonquick.com/u/David_Wong)\
**Post date:** [June 5, 2024, 6:16am UTC](https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881/2 "2024-06-05T06:16:06Z")

</div>

Hi @HarveyB-B,

You can’t use both an aggregated value (MinArrearsDate) and an unaggregated value (now) in your calculation. Try to calculate MinArrearsDate using minOver instead:

```auto
minOver(IntoArrears, [applicantid], PRE_AGG)

```

---

<div class="post-metadata">

**Author:** ![HarveyB-B](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@HarveyB-B](https://community.amazonquick.com/u/HarveyB-B)\
**Post date:** [June 7, 2024, 8:32am UTC](https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881/3 "2024-06-07T08:32:41Z")

</div>

So i think my date field is also mismatched

I try this field:

ifelse({AccountingPeriodDate} = max({AccountingPeriodDate}), dateDiff({MinArrearsDateV2}, now()), dateDiff({MinArrearsDateV2}, {AccountingPeriodDate}))

For context:  
MinArrearsDateV2 =  
minOver(IntoArrears, [applicantid], PRE\_AGG)

AccountingPeriodDate = parseDate(AccountingPeriodDateFormatStr, ‘yyyy/MM/dd’)

Look at attached Q/A at the top of this forum for breakdown of the AccountingPeriodDate field

I get the result that ifelse({AccountingPeriodDate} = max({AccountingPeriodDate}) is mismatched aggregation

---

<div class="post-metadata">

**Author:** ![Xclipse](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/xclipse/32/20455_2.png) [@Xclipse](https://community.amazonquick.com/u/Xclipse)\
**Post date:** [June 28, 2024, 3:37am UTC](https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881/4 "2024-06-28T03:37:17Z")

</div>

Hi @HarveyB-B, in case you need further assistance with your problem, please create a sample dashboard with sample dataset showing your problem state using Arena and please create a new post, so we can look at it from a fresh perspective. (Details on using Arena can be found here - [Quick Sight Arena](https://community.amazonquick.com/t/quicksight-arena-an-embedded-instance-of-quicksight-within-the-quicksight-community/21437))

---

<div class="post-metadata">

**Author:** ![Xclipse](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/xclipse/32/20455_2.png) [@Xclipse](https://community.amazonquick.com/u/Xclipse)\
**Post date:** [June 28, 2024, 3:37am UTC](https://community.amazonquick.com/t/date-difference-between-aggregated-and-non-aggregated-field/30881/5 "2024-06-28T03:37:35Z")

</div>

Archived on June 28, 2024, 3:37am UTC


