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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Return Week number based on best week sales

Hi,

I have the following table of total sold by Week.

I am trying to extract just the Week of the best selling (max total sold from Year to selected date) so that I can put it onto a single value card.

I can get the value of the best total sales week with this formula

Total BW =
VAR year = SELECTEDVALUE('Date'[Year])
VAR Week = SELECTEDVALUE('Date'[YearWeek])
RETURN
MAXX( FILTER('MyTable', 'MyTable'[Year] = year && 'MyTable'[YearWeek] < Week),'MyTable)

I would appreciate it if somebody can help me to retrieve only the Week corresponding to the Best week sales.Thanks

 

Year YearWeek Week Total sold

20212021-34341
20212021-33331
20212021-31311
20212021-27273
20212021-26263
20212021-25253
20212021-242448
20212021-2323238
20212021-2222310
20212021-2121331
20212021-2020245
20212021-1919249
20212021-1818281
20212021-1717219
20212021-1616283
20212021-1515254
20212021-1414294
20212021-1313306
20212021-1212288
20212021-1111249
20212021-1010237
20212021-099283
20212021-088229
20212021-077308
20212021-066239
20212021-055300
20212021-044237
20212021-033206
20212021-022157
3 ACCEPTED SOLUTIONS
Nathaniel_C
Super User
Super User

Hi @Anonymous , try this:

Highest Week = 
var _maxSold= MAX(myTable[Total Sold]) // get the highest weekly sold

var _calc =CALCULATE(MAX(myTable[Week]),myTable[Total Sold]=_maxSold)

return _calc


Capturefian1.PNG

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Try these measures:

Total sales = SUM(Data[Total sold])
Best selling week = FIRSTNONBLANK ( TOPN ( 1, VALUES ( Data[Week] ), [Total Sales] ), 1 )

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

sktneer
Resolver I
Resolver I

Another way to achieve this...

 

Assuming the name of your table is Sales then try this...

 

Week with highest sale =
CONCATENATEX (
    TOPN (
        1,
        Sales,
        Sales[Total sold]
    ),
    Sales[Week],
    ", ",
    Sales[Total sold], DESC
)

View solution in original post

3 REPLIES 3
sktneer
Resolver I
Resolver I

Another way to achieve this...

 

Assuming the name of your table is Sales then try this...

 

Week with highest sale =
CONCATENATEX (
    TOPN (
        1,
        Sales,
        Sales[Total sold]
    ),
    Sales[Week],
    ", ",
    Sales[Total sold], DESC
)
Ashish_Mathur
Super User
Super User

Hi,

Try these measures:

Total sales = SUM(Data[Total sold])
Best selling week = FIRSTNONBLANK ( TOPN ( 1, VALUES ( Data[Week] ), [Total Sales] ), 1 )

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Nathaniel_C
Super User
Super User

Hi @Anonymous , try this:

Highest Week = 
var _maxSold= MAX(myTable[Total Sold]) // get the highest weekly sold

var _calc =CALCULATE(MAX(myTable[Week]),myTable[Total Sold]=_maxSold)

return _calc


Capturefian1.PNG

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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