Forum Discussion

Juli2102's avatar
Juli2102
Frequent Visitor
3 years ago
Solved

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!

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    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:

     

    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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    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:

     

    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