Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
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('Database Export'[Nb Sales]),(FILTER('Database Export', 'Database Export'[Weeks Since Launch]=MAX('Database Export'[Weeks Since Launch]))))
Where "Weeks Since Launch" is just a standard integer.
However my data source has changed it's formatting slightly and I now need to take the second highest value from the weeks since launch and not the highest. Is there an easy way to pull this number? I'm assuming I'd need something that functions similarly to a 'LARGE' command in excel?
Thanks in Advance
Hi @Petersfield
I'm wondering if we can take advantage of the RANK function and then look for items where RANK = 2 ???
Do you have some sample data we can try this on?
Hey Phil!
Sure, here's an example below of one product for one territory. What I would be looking to do is display is the Sum of the second highest week since launches sales, and then if possible the percentage change between the second higest and third highest week since launch.
Thanks!
Date | Platform | Title | Sales Territory | Measure Name | Sales | Weeks Since Launch |
20/03/2017 | MS1 | WDD2.1 | United States | WAU | 42016 | 19 |
13/03/2017 | MS1 | WDD2.1 | United States | WAU | 118464 | 18 |
06/03/2017 | MS1 | WDD2.1 | United States | WAU | 114464 | 17 |
27/02/2017 | MS1 | WDD2.1 | United States | WAU | 121696 | 16 |
20/02/2017 | MS1 | WDD2.1 | United States | WAU | 136992 | 15 |
13/02/2017 | MS1 | WDD2.1 | United States | WAU | 129920 | 14 |
06/02/2017 | MS1 | WDD2.1 | United States | WAU | 159072 | 13 |
30/01/2017 | MS1 | WDD2.1 | United States | WAU | 175328 | 12 |
23/01/2017 | MS1 | WDD2.1 | United States | WAU | 183552 | 11 |
16/01/2017 | MS1 | WDD2.1 | United States | WAU | 191936 | 10 |
09/01/2017 | MS1 | WDD2.1 | United States | WAU | 208384 | 9 |
02/01/2017 | MS1 | WDD2.1 | United States | WAU | 265792 | 8 |
26/12/2016 | MS1 | WDD2.1 | United States | WAU | 316896 | 7 |
19/12/2016 | MS1 | WDD2.1 | United States | WAU | 192544 | 6 |
12/12/2016 | MS1 | WDD2.1 | United States | WAU | 104544 | 5 |
05/12/2016 | MS1 | WDD2.1 | United States | WAU | 116736 | 4 |
28/11/2016 | MS1 | WDD2.1 | United States | WAU | 135296 | 3 |
21/11/2016 | MS1 | WDD2.1 | United States | WAU | 160672 | 2 |
14/11/2016 | MS1 | WDD2.1 | United States | WAU | 128320 | 1 |
20/03/2017 | P4S | WDD2.1 | United States | WAU | 49024 | 19 |
13/03/2017 | P4S | WDD2.1 | United States | WAU | 129856 | 18 |
06/03/2017 | P4S | WDD2.1 | United States | WAU | 130400 | 17 |
27/02/2017 | P4S | WDD2.1 | United States | WAU | 148800 | 16 |
20/02/2017 | P4S | WDD2.1 | United States | WAU | 167488 | 15 |
13/02/2017 | P4S | WDD2.1 | United States | WAU | 146496 | 14 |
06/02/2017 | P4S | WDD2.1 | United States | WAU | 184480 | 13 |
30/01/2017 | P4S | WDD2.1 | United States | WAU | 199168 | 12 |
23/01/2017 | P4S | WDD2.1 | United States | WAU | 213344 | 11 |
16/01/2017 | P4S | WDD2.1 | United States | WAU | 235136 | 10 |
09/01/2017 | P4S | WDD2.1 | United States | WAU | 240128 | 9 |
02/01/2017 | P4S | WDD2.1 | United States | WAU | 312512 | 8 |
26/12/2016 | P4S | WDD2.1 | United States | WAU | 377952 | 7 |
19/12/2016 | P4S | WDD2.1 | United States | WAU | 245920 | 6 |
12/12/2016 | P4S | WDD2.1 | United States | WAU | 146400 | 5 |
05/12/2016 | P4S | WDD2.1 | United States | WAU | 163552 | 4 |
28/11/2016 | P4S | WDD2.1 | United States | WAU | 192160 | 3 |
21/11/2016 | P4S | WDD2.1 | United States | WAU | 224256 | 2 |
14/11/2016 | P4S | WDD2.1 | United States | WAU | 175520 | 1 |
20/03/2017 | iPC | WDD2.1 | United States | WAU | 3712 | 19 |
13/03/2017 | iPC | WDD2.1 | United States | WAU | 10112 | 18 |
06/03/2017 | iPC | WDD2.1 | United States | WAU | 11776 | 17 |
27/02/2017 | iPC | WDD2.1 | United States | WAU | 12768 | 16 |
20/02/2017 | iPC | WDD2.1 | United States | WAU | 15904 | 15 |
13/02/2017 | iPC | WDD2.1 | United States | WAU | 17504 | 14 |
06/02/2017 | iPC | WDD2.1 | United States | WAU | 17952 | 13 |
30/01/2017 | iPC | WDD2.1 | United States | WAU | 21248 | 12 |
23/01/2017 | iPC | WDD2.1 | United States | WAU | 23296 | 11 |
16/01/2017 | iPC | WDD2.1 | United States | WAU | 33344 | 10 |
09/01/2017 | iPC | WDD2.1 | United States | WAU | 33824 | 9 |
02/01/2017 | iPC | WDD2.1 | United States | WAU | 40448 | 8 |
26/12/2016 | iPC | WDD2.1 | United States | WAU | 50848 | 7 |
19/12/2016 | iPC | WDD2.1 | United States | WAU | 40608 | 6 |
12/12/2016 | iPC | WDD2.1 | United States | WAU | 36768 | 5 |
05/12/2016 | iPC | WDD2.1 | United States | WAU | 45024 | 4 |
28/11/2016 | iPC | WDD2.1 | United States | WAU | 45152 | 3 |
21/11/2016 | iPC | WDD2.1 | United States | WAU | 224 | 2 |
Hi @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) ) + 1
This 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) )
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
Hi,
New to PBI and I hope it's ok that I continue this topic.
Have a question for @Phil_Seamark
I have a very similar situation as the original question though I'm trying to rank days of a year from 1-364 (yes 364, I'm missing the last day of the year).
However I run into trouble when multiple days have the same numerical value I want to rank. For instance I have two days, April 23 and October 15, both with a value of 2034 and they each get assigned rank number 42. And there are a few other such instances. This means that I end up with a table of 360 distinct rank values, where I'd hoped to have 364.
I've tried adding filtering options to your "Ranking on week sales" to get around this problem but I can't seem to figure it out. Let's say I want the date which comes first in the year (April 23) to have rank 42, and October 15 to get rank 43.
Can you pleas help me, or point me in the right direction.
Cheers,
Oscar
Morning,
Thought I could attache a file in a privat message but cant't find th option so here comes som data from me.
I've copied your ranking code but in any case this is my code:
Rank A -> B = var currentDay = 'Datum'[Yearly Max Flow A -> B] return COUNTROWS( FILTER( ALL('Datum'[Yearly Max Flow A -> B]); 'Datum'[Yearly Max Flow A -> B] > (currentDay ) ) ) +1
This gives the highest value in column [Yearly Max Flow A -> B] rank 1, and so on.
Date Yearly Max Flow A -> B Yearly Max Flow B -> A 2017-05-19 00:00 2572,833333 1863,5 2017-09-21 00:00 2562,833333 1678,5 2017-03-24 00:00 2366,666667 1724,25 2017-09-01 00:00 2255,25 1877 2017-08-22 00:00 2240,083333 1914,5 2017-09-26 00:00 2215,916667 2158,5 2017-06-22 00:00 2193,166667 1515 2017-04-03 00:00 2190,083333 1991 2017-11-26 00:00 2187,5 2110,5 2017-09-08 00:00 2182,166667 1582,5 2017-05-16 00:00 2181,333333 1874,25 2017-09-29 00:00 2176,166667 1771 2017-07-28 00:00 2152,666667 1644,5 2017-09-22 00:00 2138,25 1676,583333 2017-04-27 00:00 2136,75 1798,5 2017-06-30 00:00 2129,5 1687,5 2017-10-01 00:00 2122,25 1657 2017-12-11 00:00 2118 1666,25 2017-05-04 00:00 2117,833333 1978,25 2017-09-06 00:00 2108,583333 1736,5 2017-09-24 00:00 2098,75 1874,666667 2017-06-29 00:00 2095,916667 1502,5 2017-09-18 00:00 2094,583333 1603,25 2017-06-08 00:00 2093,916667 1851,5 2017-03-28 00:00 2093,25 2247,166667 2017-10-16 00:00 2086,75 1831 2017-10-06 00:00 2085,333333 1543,916667 2017-06-16 00:00 2080,25 1941 2017-12-05 00:00 2076 2075,25 2017-06-04 00:00 2072,25 1537,083333 2017-07-02 00:00 2065,083333 1399,333333 2017-05-14 00:00 2064,416667 2082,333333 2017-11-15 00:00 2063,75 1918,75 2017-08-10 00:00 2060,5 1539,166667 2017-09-11 00:00 2056,666667 1716,25 2017-06-18 00:00 2056,5 1500 2017-04-07 00:00 2050,416667 1778,75 2017-11-06 00:00 2049,75 1986,5 2017-11-27 00:00 2044,333333 1791,5 2017-09-13 00:00 2044,25 1864,5 2017-04-09 00:00 2041,75 2089,25 2017-04-23 00:00 2034 1611,5 2017-10-15 00:00 2034 1481
These are the 43 highest values in the column A -> B (Middle) however as acn be seen, the last two entries are equal (2034) and thus with "my" code both get rank 42.
Thanks for the help!
Cheers,
Oscar
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
124 | |
114 | |
74 | |
65 | |
46 |