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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Greg25
New Member

Normalize time series data for display in Line Chart

Hi all,

 

I would like to display two time series in a normalized way to see their performance relative to each other. Think about two stocks (e.g. Apple vs. Microsoft) and I would like to visualized which stock performs better in this year. 

 

An example what I look for

2021-12-07 13_06_14-Clipboard.png

 

The "problem" is that each time I change the date range, for which the data is displayed, the normalization to zero percent has to be recalculated since it depends on the visual. 

 

My tables and model look like this

2021-12-07 13_12_22-Example - Power BI Desktop.png

2021-12-07 13_13_15-Example - Power BI Desktop.png         Greg25_0-1638879401382.png

 

Please find the full model and data at https://drive.google.com/file/d/1dU_ZGyb9QjeWbM-etW83Vq9D_l-ljMr5/view?usp=sharing

 

My problem is somehow similar as https://community.powerbi.com/t5/Desktop/Normalize-time-series-data-to-first-non-zero/m-p/598559#M28... from @Anonymous but the solution doesn't work for my case.

 

I tried (as newbie) myself to create a line chart based on the above mentioned solution but I cannot get it to work despite using around 20 hours for it. My code looks like this but isn't working.

 

 

ChangeIndex% = 

VAR a =
    CALCULATE (
        MAX ( 'IndexData'[index1_close] ),
        FILTER (
            'IndexData',
            'IndexData'[DateIndex] = MIN ( 'IndexData'[DateIndex]  )
        )
    )
VAR mindate =
    CALCULATE (
        MIN ( 'IndexData'[DateIndex]  ),
        ALLSELECTED ( 'IndexData'[DateIndex]  )
    )

VAR firstrecord =
    CALCULATE (
        MAX ( 'IndexData'[index1_close]),
        FILTER (
            ALLSELECTED ( 'IndexData' ),
            'IndexData'[DateIndex] = mindate)
    )
RETURN
    DIVIDE ( a - firstrecord, firstrecord )

 

 

 

My two problems with the code are

  1. The calculation delivers the wrong percentage.
  2. If I would use this code twice (for each index), I would always get a circular dependency that I cannot resolve. 

 

Any help would be appreciated! Thank you!

 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

I looked at your file.  A few comments

  • You should use measures where possible instead of calculated columns
  • You should change the relationship to be a single-direction and 1:M
  • You should unpivot your data to make your analysis easier (i.e., your index1 and index2 values should be in the same column with a second column with the values of index1 and index2). That way you can use that second column as the legend in your visuals.
  • Below is an example measure for Index1 (I couldn't change your query to unpivot your data, so two measures still needed)
  • Attached is the modified pbix file, if useful

mahoneypat_0-1638918376567.png

 

Rel Change 1 =
VAR vThisValue =
    MAX ( IndexData[index1_close] )
VAR vFirstDate =
    CALCULATE ( MIN ( IndexData[DateIndex] )ALLSELECTED ( IndexData[DateIndex] ) )
VAR vFirstClose =
    CALCULATE (
        MAX ( IndexData[index1_close] ),
        ALL ( 'Date' ),
        IndexData[DateIndex] = vFirstDate
    )
RETURN
    DIVIDE ( vThisValue - vFirstClosevFirstClose )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

I looked at your file.  A few comments

  • You should use measures where possible instead of calculated columns
  • You should change the relationship to be a single-direction and 1:M
  • You should unpivot your data to make your analysis easier (i.e., your index1 and index2 values should be in the same column with a second column with the values of index1 and index2). That way you can use that second column as the legend in your visuals.
  • Below is an example measure for Index1 (I couldn't change your query to unpivot your data, so two measures still needed)
  • Attached is the modified pbix file, if useful

mahoneypat_0-1638918376567.png

 

Rel Change 1 =
VAR vThisValue =
    MAX ( IndexData[index1_close] )
VAR vFirstDate =
    CALCULATE ( MIN ( IndexData[DateIndex] )ALLSELECTED ( IndexData[DateIndex] ) )
VAR vFirstClose =
    CALCULATE (
        MAX ( IndexData[index1_close] ),
        ALL ( 'Date' ),
        IndexData[DateIndex] = vFirstDate
    )
RETURN
    DIVIDE ( vThisValue - vFirstClosevFirstClose )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you so much, Pat.

 

Great solution, thank you so much! I just found one little thing that needs to be changed from your script. In your script, when I change the data it does not normalize to zero to the new data but it normalizes to the first date (end of 2019).

 

Original version:

Greg25_0-1638957888841.png

Greg25_1-1638957923030.png

With a little change, I get the desired result:

Greg25_2-1638958047790.png

The change from PAT's DAX is as follows:

 

Rel Change 1 = 
VAR vThisValue =
    MAX ( IndexData[index1_close] )
VAR vFirstDate =
    CALCULATE ( MIN ( IndexData[DateIndex] ), ALLSELECTED( IndexData[DateIndex] ) )
VAR vFirstClose =
    CALCULATE (
        MAX ( IndexData[index1_close] ),
        ALL ( 'Date' ),
        IndexData[DateIndex] = vFirstDate
    )
RETURN
    DIVIDE ( vThisValue - vFirstClose, vFirstClose )

 

The Change is from 

 

ALL

 

to 

 

ALLSELECTED

 

@mahoneypat: Could you, please, update your post with this change so that people later find this change in the accepted solution?



 

Glad it worked.  Updated with ALLSELECTED.

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.