cancel
Showing results for
Did you mean:
Frequent Visitor

## Difference between values in a single column based on an identifying value

Hi there community!

I'm working with a dataset in which I'm trying to display on Customer and Article level the sales Amount. This is done by looking at a set of seperate Excel files all with their own date of uploading (represented by File Date). These seperate files are combined in to one query by using the append queries function, and File Date functions as an identifying column to be able to differentiate between the seperate files that have been combined in to one query.

I have built a small dataset to give an idea on what kind of data I'm working with:

CustomerDelivery DateArticleAmountFile Date

 1 23-10-2021 999 100 1-1-2022 1 12-12-2021 999 500 1-2-2022 1 30-12-2021 212 400 1-3-2022 1 15-1-2022 487 150 1-3-2022 1 18-3-2022 212 300 1-4-2022 2 12-12-2021 476 300 1-1-2022 2 23-5-2022 98 1000 1-2-2022 2 25-5-2022 146 20 1-2-2022 2 30-7-2022 999 500 1-3-2022 2 5-8-2022 358 700 1-5-2022 2 10-10-2022 487 100 1-4-2022 3 15-11-2021 564 500 1-1-2022 3 30-1-2022 999 400 1-3-2022 3 2-2-2022 154 50 1-3-2022 3 24-7-2022 308 800 1-5-2022

The data will be presented to the user in a matrix similar to the one below:

The user will be expanding this matrix to also get a detailed view on Article level, which would look something like this:

Using the matrices presented above I want to be able to compare values and show the differences. If Customer = 1 this would mean that the first matrix should also show the following values:

• +400 for the difference between 1-1-2022 and 1-2-2022
• +50 for the difference between 1-2-2022 and 1-3-2022
• -250 for the difference between 1-3-2022 and 1-4-2022
• -300 for the difference between 1-4-2022 and 1-5-2022

Ideally this difference is shown in percentages but to get it calculated in absolute numbers is a start. I have been struggling with this for a while now and I'm reaching out for suggestions as to how I can get a measure/column implemented to reach the desired result.

Looking forward to your suggestions and many thanks in advance!

1 ACCEPTED SOLUTION
Community Support

Hi @hassaanb_ ,

``````% (Customer level) =
var _nextDate= MINX(FILTER(ALL('Table'),[Customer]=MAX('Table'[Customer])&& [File Date]>MAX('Table'[File Date])),[File Date])
var _diff=CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'), [Customer]=MAX('Table'[Customer]) &&[File Date]=_nextDate ))-SUM('Table'[Amount])
return DIVIDE(_diff,SUM('Table'[Amount]))``````

Or

``````% (Article level) =
var _nextDate= MINX(FILTER(ALL('Table'),[Customer]=MAX('Table'[Customer])&&[Article]=MAX('Table'[Article])  && [File Date]>MAX('Table'[File Date])),[File Date])
var _nextSum=CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'), [Customer]=MAX('Table'[Customer])&&[Article]=MAX('Table'[Article])&&[File Date]=_nextDate ))
var _current=CALCULATE(SUM('Table'[Amount]),FILTER('Table', [Customer]=MAX('Table'[Customer])&&[Article]=MAX('Table'[Article])))
return  DIVIDE( _nextSum-_current, _current)``````

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support

Hi @hassaanb_ ,

``````% (Customer level) =
var _nextDate= MINX(FILTER(ALL('Table'),[Customer]=MAX('Table'[Customer])&& [File Date]>MAX('Table'[File Date])),[File Date])
var _diff=CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'), [Customer]=MAX('Table'[Customer]) &&[File Date]=_nextDate ))-SUM('Table'[Amount])
return DIVIDE(_diff,SUM('Table'[Amount]))``````

Or

``````% (Article level) =
var _nextDate= MINX(FILTER(ALL('Table'),[Customer]=MAX('Table'[Customer])&&[Article]=MAX('Table'[Article])  && [File Date]>MAX('Table'[File Date])),[File Date])
var _nextSum=CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'), [Customer]=MAX('Table'[Customer])&&[Article]=MAX('Table'[Article])&&[File Date]=_nextDate ))
var _current=CALCULATE(SUM('Table'[Amount]),FILTER('Table', [Customer]=MAX('Table'[Customer])&&[Article]=MAX('Table'[Article])))
return  DIVIDE( _nextSum-_current, _current)``````

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Announcements

#### The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

#### Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

#### Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors