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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
nexaframe
Frequent Visitor

Calculate Value Change / Value Difference between given Dates

Hello Community,

as I could not find any answer here or on other platforms, I would like to get your support with my first contribution:

 

I have a dataset of stock reports looking basically like this:  UpdateDate, Type and Value.

For each ReportDate only Types with a Value are included. That means, if a Type is reduced to 0 between two reports, it will not be indicated, they just disappear. New Types can also show in newer reports without previous data.

 

ReportDateTypeValue
5/10/202212310
5/16/202212310
5/23/202212310
5/10/202234520
5/10/202245650
5/16/202245650
5/23/202245620
5/23/202256715
5/16/202278925
5/23/202278930

 

I want to see the changes of  the values. An example for the output would be (grouping by Type, for better understanding only)

 

Type/CalendarDate5/10/20225/16/20225/23/2022
123+1000
345+20-200
456+500-30
56700+15
7890+25+5

 

As the reports are not provided in a regular way, I created in the first step a CalendarTable and linked it to my dataset.

But then I am struggling with the start/end date to filter my calculation.

I guess I need variables indicating the last value, last date of the value and somehow an indicator that it is treated as zero, if there is no value for the type at a selected date.

 

Hope you have some suggestions.

Thank you!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @nexaframe ,

Please refer to my pbix file to see if it helps you.

Create  a table.

Table 2 = VALUES('Table'[ReportDate])

Then put the table 2 [reportdate] into the column filed.

Create two measures.

Measure =
VAR _oreplrblank =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Type]
                IN VALUES ( 'Table'[Type] )
                    && 'Table'[ReportDate] IN VALUES ( 'Table 2'[ReportDate] )
        )
    )
VAR _harereplace =
    IF ( _oreplrblank = BLANK (), 0, _oreplrblank )
RETURN
    _harereplace
Measure_2 =
VAR _DATEBEFORE =
    CALCULATE (
        MAX ( 'Table 2'[ReportDate] ),
        FILTER (
            ALL ( 'Table 2' ),
            'Table 2'[ReportDate] < MAX ( 'Table 2'[ReportDate] )
        )
    )
VAR _VALUEBEFORE =
    CALCULATE (
        [Measure],
        FILTER ( ALL ( 'Table 2' ), 'Table 2'[ReportDate] = _DATEBEFORE )
    )
RETURN
    [Measure] - _VALUEBEFORE

vpollymsft_0-1653555758615.png

 

Best Regards

Community Support Team _ Polly

 

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

7 REPLIES 7
Anonymous
Not applicable

Hi @nexaframe ,

It works well. Could you please provide your pbix file without privacy information for me to study?

"The "total" calculation is not working."

Please refer to it.

Dealing with Measure Totals 

 

Or create a measure base on measure_2.

Measure_3 =
VAR _a = [Measure_2]
VAR _b =
    SUMMARIZE ( 'Table', 'Table'[Type], "aaa", [Measure_2] )
RETURN
    IF ( ISINSCOPE ( 'Table'[Type] ), _a, SUMX ( _b, [aaa] ) )

vpollymsft_0-1653613991091.png

Best Regards

Community Support Team _ Polly

 

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

Hello and thank you again,

as I can't find a solution to upload it here, I can share it via this link: here 

Anonymous
Not applicable

Hi @nexaframe ,

We have create a table2 before.

Then put the table 2 [reportdate] into the column filed in the matrix!

 

vpollymsft_2-1653619435227.png

 

Best Regards

Community Support Team _ Polly

 

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

Anonymous
Not applicable

Hi @nexaframe ,

Please refer to my pbix file to see if it helps you.

Create  a table.

Table 2 = VALUES('Table'[ReportDate])

Then put the table 2 [reportdate] into the column filed.

Create two measures.

Measure =
VAR _oreplrblank =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Type]
                IN VALUES ( 'Table'[Type] )
                    && 'Table'[ReportDate] IN VALUES ( 'Table 2'[ReportDate] )
        )
    )
VAR _harereplace =
    IF ( _oreplrblank = BLANK (), 0, _oreplrblank )
RETURN
    _harereplace
Measure_2 =
VAR _DATEBEFORE =
    CALCULATE (
        MAX ( 'Table 2'[ReportDate] ),
        FILTER (
            ALL ( 'Table 2' ),
            'Table 2'[ReportDate] < MAX ( 'Table 2'[ReportDate] )
        )
    )
VAR _VALUEBEFORE =
    CALCULATE (
        [Measure],
        FILTER ( ALL ( 'Table 2' ), 'Table 2'[ReportDate] = _DATEBEFORE )
    )
RETURN
    [Measure] - _VALUEBEFORE

vpollymsft_0-1653555758615.png

 

Best Regards

Community Support Team _ Polly

 

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

Hello @Anonymous 

Thanks for your support.

Somehow it works in your attached file, but when I copy the exact same solution to the test data, it doesn't?

Unfortunately I can not upload the file here?

 

Also seeing your solution: The "total" calculation is not working by type and also not by date?

 

Any help is really appreciated.

Thank you!

nexaframe_0-1653557923728.png

 

amitchandak
Super User
Super User

@nexaframe , Try a new column like

 

Diff with last date =
var _1 = maxx(filter(Table, Table[Type] = earlier(Table[Type]) && [ReportDate] < earlier([ReportDate])),[ReportDate])
return
[Value] - maxx(filter(Table, Table[Type] = earlier(Table[Type]) && [ReportDate] < earlier([ReportDate])),[Value])

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandakthanks for your super fast reply. Unfortunately it works only partially.

- It works if there is data for a type on all reportdates and it works if a new type is popping up on a later report date and not from the beginning. BUT: It doesn't work if a type just disappears.

In my example above, the issue is with Type "345", it shows "20 on the first date, but than empty columns for the rest. Expected would be "-20" on the next date, then later 0.

Do you have any suggestions?

 

Thank you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors