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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
powerbidu
Frequent Visitor

write measure/dax to calculate min max and % difference

DateIdentifierOrder NumberPrice
1-OctA1231.15
1-OctA1231.15
1-OctA1241.00
1-OctA1251.20
1-OctB1262.00
1-OctB1262.20
1-OctC1273.10
1-OctC1283.00
1-OctC1293.20

 

Hello, I have the table above. For instance, identifier A appears four times on 1st October. I would like to create formulas that display the minimum price (1.0), maximum price (1.2), and the percentage difference between the minimum and maximum price, calculated as ((1.2 - 1.0) / 1.0 = 20%).

 

I want these calculations to be applicable to all identifiers that have different order numbers for the same identifier (meaning I won't perform the calculations for identifier B, which has only one order number, but I would for identifier C).

 

Ideally, I would like to plot these values in a bar chart, with the X-axis representing the identifiers and the Y-axis showing the minimum, maximum, and percentage change, resembling trading candlestick patterns. Appreciate any advice. Thank you.

 
1 ACCEPTED SOLUTION
rubayatyasmin
Super User
Super User

Hi, @powerbidu 

 

MaxPrice =
VAR OrderCount = CALCULATE(DISTINCTCOUNT(Data[Order Number]), ALLEXCEPT(Data, Data[Identifier]))
RETURN
IF(OrderCount > 1, CALCULATE(MAX(Data[Price]), ALLEXCEPT(Data, Data[Identifier])))

 

Same for Min, change the MAX to Min. 

 

PercentageChange = DIVIDE([MaxPrice] - [MinPrice], [MinPrice], 0)

 

rubayatyasmin_0-1742663589214.png

Refer to the attached pbix file. 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

4 REPLIES 4
v-ssriganesh
Community Support
Community Support

Hi @powerbidu,
Thank you for reaching out to the Microsoft Fabric community forum.

I have reproduced your scenario using Power BI and created the required DAX measures to calculate the Minimum Price, Maximum Price, and Percentage Difference based on your dataset. The calculations ensure that the measures apply only when an identifier has multiple distinct Order Numbers.

Below are the DAX measures used:

Measure 1: Count Distinct Order Numbers

This measure counts the unique Order Number values per Date and Identifier.

DistinctOrderCount =

CALCULATE(

    DISTINCTCOUNT('PriceTable'[Order Number]),

    ALLEXCEPT('PriceTable', 'PriceTable'[Date], 'PriceTable'[Identifier])

)

Measure 2: Minimum Price

Returns the minimum price only if the identifier has more than one distinct order number.

MinPrice =

IF(

    [DistinctOrderCount] > 1,

    CALCULATE(

        MIN('PriceTable'[Price]),

        ALLEXCEPT('PriceTable', 'PriceTable'[Date], 'PriceTable'[Identifier])

    ),

    BLANK()

)

Measure 3: Maximum Price

Returns the maximum price under the same condition as above.

MaxPrice =

IF(

    [DistinctOrderCount] > 1,

    CALCULATE(

        MAX('PriceTable'[Price]),

        ALLEXCEPT('PriceTable', 'PriceTable'[Date], 'PriceTable'[Identifier])

    ),

    BLANK()

)

Measure 4: Percentage Difference

Calculates the percentage difference between Max and Min Price.

PercentDifference =

IF(

    [DistinctOrderCount] > 1,

    DIVIDE(

        [MaxPrice] - [MinPrice],

        [MinPrice],

        0

    ) * 100,

    BLANK()

)


I have attached a screenshot showing the expected output and a .pbix file for your reference.

vssriganesh_0-1742801524307.png

 



Also, thanks @Deku@rubayatyasmin@techies for your valuable insights.


If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

Deku
Super User
Super User

something like this? or something else in mind?

Deku_0-1742680143376.png

 

createOrReplace
	table measures
		measure Min = MIN( 'Table'[Price] )
		measure Range = [Max] - [Min] 
		measure %Diff = DIVIDE( [Max] - [Min], [Min] )
		measure Max = MAX( 'Table'[Price] )

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
rubayatyasmin
Super User
Super User

Hi, @powerbidu 

 

MaxPrice =
VAR OrderCount = CALCULATE(DISTINCTCOUNT(Data[Order Number]), ALLEXCEPT(Data, Data[Identifier]))
RETURN
IF(OrderCount > 1, CALCULATE(MAX(Data[Price]), ALLEXCEPT(Data, Data[Identifier])))

 

Same for Min, change the MAX to Min. 

 

PercentageChange = DIVIDE([MaxPrice] - [MinPrice], [MinPrice], 0)

 

rubayatyasmin_0-1742663589214.png

Refer to the attached pbix file. 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


techies
Super User
Super User

Hi @powerbidu please check this

 

Min Price =
CALCULATE(
MIN('Table'[Price]),
ALLEXCEPT('Table', 'Table'[Identifier])
)

 

Max Price =
CALCULATE(
MAX('Table'[Price]),
ALLEXCEPT('Table', 'Table'[Identifier])
)

 

% Difference =
VAR MinPrice = [Min Price]
VAR MaxPrice = [Max Price]
RETURN
IF(
MinPrice > 0,
DIVIDE(MaxPrice - MinPrice, MinPrice, 0),
BLANK()
)

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors