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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MAP
Frequent Visitor

Shares price match with previous price

I am currently working on stock market data in Power BI and need to create a DAX measure that identifies when a stock’s price approximately matches a given value on previous days. For example, if the price of XYZ shares is 120, I want to find out when the price of XYZ shares was approximately 120 on previous days.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from Rakesh1705 and SachinNandanwar  , please allow me to provide another insight:

Hi, @MAP 

Can you tell me if your problem is solved? If yes, please accept
their as solution.
 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1723449047932.png

2.First, you can try using the following calculation table, using its id column as a slicer:

Table 2 = SELECTCOLUMNS('Table','Table'[ID],'Table'[date])

3.Second, use the following measures and modify the filters:

MEASURE =
VAR nday =
    MAX ( 'Table 2'[Table_date] )
VAR nprice =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[date] = nday ),
        'Table'[price]
    )
VAR selce11 =
    MAX ( 'Table 2'[Table_ID] )
RETURN
    IF (
        ISFILTERED ( 'Table 2'[Table_ID] ),
        IF (
            ABS ( MAX ( 'Table'[price] ) - nprice ) < 1
                && MAX ( 'Table'[ID] ) = selce11,
            1,
            0
        ),
        1
    )

4.Here's my final result, which I hope meets your requirements.

 

vlinyulumsft_1-1723449166760.png

 

 

vlinyulumsft_2-1723449166761.png

vlinyulumsft_3-1723449184304.png

 


 

Please find the attached pbix relevant to the case.

 
Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

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

5 REPLIES 5
Rakesh1705
Super User
Super User

Since I dont have your sample data and your idea of approximate price, I have implemented my idea here.
I have taken all the historical data of tata motors from Yahoo finance.

Source Data

Rakesh1705_0-1723308098417.png

First the closing price is rounded off

Rakesh1705_1-1723308141986.png

Now latest price is found

Rakesh1705_2-1723308210689.png

Starting digit of latest price is found

Rakesh1705_3-1723308243170.png

Number of digits in the latest price is found

Rakesh1705_4-1723308270321.png

Nearest Lowest round figure is found

Rakesh1705_5-1723308295520.png

Nearest highest round figure is found

Rakesh1705_6-1723308324839.png

Required date indicators is found

Rakesh1705_7-1723308351705.png

Filtered the "Price Indicator" text in the final column

Rakesh1705_8-1723308404141.png

I hope you have your answer. If my answer is satisfying with your criteria then please accept the same as your solution.

Thank you for replying. I'll see if your answer fulfills what I want.

Anonymous
Not applicable

Thanks for the reply from Rakesh1705 and SachinNandanwar  , please allow me to provide another insight:

Hi, @MAP 

Can you tell me if your problem is solved? If yes, please accept
their as solution.
 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1723449047932.png

2.First, you can try using the following calculation table, using its id column as a slicer:

Table 2 = SELECTCOLUMNS('Table','Table'[ID],'Table'[date])

3.Second, use the following measures and modify the filters:

MEASURE =
VAR nday =
    MAX ( 'Table 2'[Table_date] )
VAR nprice =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[date] = nday ),
        'Table'[price]
    )
VAR selce11 =
    MAX ( 'Table 2'[Table_ID] )
RETURN
    IF (
        ISFILTERED ( 'Table 2'[Table_ID] ),
        IF (
            ABS ( MAX ( 'Table'[price] ) - nprice ) < 1
                && MAX ( 'Table'[ID] ) = selce11,
            1,
            0
        ),
        1
    )

4.Here's my final result, which I hope meets your requirements.

 

vlinyulumsft_1-1723449166760.png

 

 

vlinyulumsft_2-1723449166761.png

vlinyulumsft_3-1723449184304.png

 


 

Please find the attached pbix relevant to the case.

 
Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

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

 


 

SachinNandanwar
Super User
Super User

Hi @MAP 

Are there any business rules that defines how close the approximate value should be ? For example if price was 80 so would that be considered close to 120 ?



Regards,
Sachin
Check out my Blog

If price is 120 then 120.01 to 120.99 will be consider close

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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