Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Juli2102
Frequent Visitor

Calculating difference in historical data for multiple items

Hello, 

 

I am struggling with some calculations in PowerBI:

I have a data table that contains about 100 vehicles with multipe columns and appropriate information.

This data table is a SharePoint-Online list. Since not only the actual data is relevant, but also the historical data to observe a develeopment is crucial, there is a PowerAutomate Flow running that saves the data table as a backup (csv) in a document library on SharePoint as well. 

 

In PowerBI I want to visualize the development of different data for the vehicles. To this purpose, the different backup files are connected to PowerBI and merged to one data table (with different timestamps). 

Now I want to calculate the difference between the timestamps to see the development (e.g. for the price development). 

A section of the table could look like this: 

 

Number of RowVehicleTimestampPriceDelta / Difference
112023-02-202000???
212023-02-101800???
312023-02-011000???
422023-02-2020000???
522023-02-1018000???
622023-02-01 17500???

 

I am interested in calculating the difference to the last table entry:
So in the first row (2023-02-20, vehicle 1) the value in column "Delta / Difference" should be 200 (=2000-1800). The last row of the appropriate vehicle should have the value 0 in column "Delta / Difference" (here: row 3 and 6).

I am aware that the calculation itself is not rocket science, I just wonder how to implement the recognition of the "vehicle change".

 

Does anybody know a solution for this problem? Can it be done within PowerQuery or do I need Dax?

 

Many thanks in advance for any kind of help!

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Juli2102 ,

 

Here are the steps you can follow:

1. Create measure.

 

Measure =
var _current=
SUMX(
FILTER(ALL('Table'),'Table'[Vehicle]=MAX('Table'[Vehicle])&&'Table'[Timestamp]=MAX('Table'[Timestamp])),[Price])
var _next=
SUMX(
    FILTER(ALL('Table'),
    'Table'[Vehicle]=MAX('Table'[Vehicle])&&
    'Table'[Timestamp]=
    MAXX(FILTER(ALL('Table'),'Table'[Vehicle]=MAX('Table'[Vehicle])&&'Table'[Timestamp]<MAX('Table'[Timestamp])),[Timestamp])),
     [Price])
return
IF(
    _next= BLANK(),
    0,
    _current - _next)

OR:

Measure 2 =
var _current=
SUMX(
    FILTER(ALL('Table'),'Table'[Vehicle]=MAX('Table'[Vehicle])&&'Table'[Number of Row]=MAX('Table'[Number of Row])),[Price])
var _next=
SUMX(
    FILTER(ALL('Table'),
    'Table'[Vehicle]=MAX('Table'[Vehicle])&&
    'Table'[Number of Row]=MAX('Table'[Number of Row])+1),
     [Price])
return
IF(
    _next= BLANK(),
    0,
    _current - _next)

2. Result:

vyangliumsft_0-1678677091707.png

 

Best Regards,

Liu Yang

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

View solution in original post

1 REPLY 1
v-yangliu-msft
Community Support
Community Support

Hi  @Juli2102 ,

 

Here are the steps you can follow:

1. Create measure.

 

Measure =
var _current=
SUMX(
FILTER(ALL('Table'),'Table'[Vehicle]=MAX('Table'[Vehicle])&&'Table'[Timestamp]=MAX('Table'[Timestamp])),[Price])
var _next=
SUMX(
    FILTER(ALL('Table'),
    'Table'[Vehicle]=MAX('Table'[Vehicle])&&
    'Table'[Timestamp]=
    MAXX(FILTER(ALL('Table'),'Table'[Vehicle]=MAX('Table'[Vehicle])&&'Table'[Timestamp]<MAX('Table'[Timestamp])),[Timestamp])),
     [Price])
return
IF(
    _next= BLANK(),
    0,
    _current - _next)

OR:

Measure 2 =
var _current=
SUMX(
    FILTER(ALL('Table'),'Table'[Vehicle]=MAX('Table'[Vehicle])&&'Table'[Number of Row]=MAX('Table'[Number of Row])),[Price])
var _next=
SUMX(
    FILTER(ALL('Table'),
    'Table'[Vehicle]=MAX('Table'[Vehicle])&&
    'Table'[Number of Row]=MAX('Table'[Number of Row])+1),
     [Price])
return
IF(
    _next= BLANK(),
    0,
    _current - _next)

2. Result:

vyangliumsft_0-1678677091707.png

 

Best Regards,

Liu Yang

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.