Forum Discussion
Petersfield
9 years agoRegular Visitor
Find the Second Highest Value
Hi All, I am new to DAX and am having trouble pulling the second largest value for a filter function. I am currently using the following the calculate the number of sales: CALCULATE(SUM('Dat...
Phil_Seamark
Microsoft Employee
9 years agoHi Petersfield
Sorry for the delay in replying
Please try adding the following 2 calculated columns to your table
Week Sales = CALCULATE(SUM('Table1'[Sales]),ALLEXCEPT('Table1',Table1[Date]))and
Ranking On Week Sales =
VAR
CurrentWeekSales = 'Table1'[Week Sales]
RETURN
COUNTROWS(
FILTER(
ALL(Table1[Week Sales]),
'Table1'[Week Sales] < CurrentWeekSales)
) + 1This assigns a ranking value to each week based on the sum of sales.
You can then build the following calculated measure on your table that use the above column (repeat for 3rd highest week) or just use the column above.
Sum of second highest week =
CALCULATE(
SUM('Table1'[Sales]),
FILTER(
'Table1',
'Table1'[Ranking On Week Sales] = 2)
)
girishsinghal
6 years agoNew Member
When I apply the first calculated column and create a table visual I get the below data.
| Platform | Week Sales |
| iPC | 6841888 |
| MS1 | 7145728 |
| P4S | 7145728 |
Can you please help me understand how I got this?
Regards,
Girish