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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Group Sales data by Year and then find peak sales

I have the following data and need the max sales grouped by year along with year in which maximum sales was done.

Expected output: 30 and 2022

Kanishka001_0-1646297174107.png

 

2 ACCEPTED SOLUTIONS

@Anonymous please try if that works for you. You need two measures:

 

 

 

Max Sales = 
Maxx ( values (Table[Year]), CALCULATE(sum(Table[Sales])))

 

 

 

 

 

MaxYear = 
var MaxSales= Maxx ( values (Tabele[Year]), CALCULATE(sum(Table[Sales])))
return 

CALCULATE(max( Table[Year]), filter ( values (Table[Year]), CALCULATE(sum(Table[Sales])= MaxSales)))

 

 

 

Hope that helps.

Best. 

View solution in original post

If you want to use TOPN -Function, this might work:

Maxx(TOPN ( 1, 
    VALUES ( Table[Year] ),
    calculate(SUM ( Table[Sales] )),
    DESC 
),Table[Year])

View solution in original post

15 REPLIES 15
Anonymous
Not applicable

Applicable88
Impactful Individual
Impactful Individual

@Anonymous, if I understand correctly that you want the sum of total sales, but only sum the max of each year? then try sth. like this:

Total Sales = Sumx( Values ( Date[Year]), Max ( 'Table'Sales))

Anonymous
Not applicable

No. I want to display the total sales of the year ( For example: for 2022 sales =10+20) which has the maximum total sales (2021 has 15, 2022 has 30, 2023 has 6). The output should be 30 and year 2022

Hi @Anonymous 
How would yoy like to disply these results? For example on a card visual? or in a matrix visual where you sluce by year and in each row you want to see the sales of the year and beside it the maxumum sales over all years and beside them the year that has the maximum sales?

Anonymous
Not applicable

On a card visual

 

@Anonymous 
You can use the following

 

MAX Sales = 
MAXX ( 
    VALUES ( 'Date'[Year] ),
    [Sales] 
)
MAX Sales Year = 
TOPN ( 1, 
    VALUES ( 'Date'[Year] ),
    [Sales],
    DESC 
)

 

Anonymous
Not applicable

No. I want to display the total sales of the year ( For example: for 2022 sales =10+20) which has the maximum total sales (2021 has 15, 2022 has 30, 2023 has 6). The output should be 30 and year 2022

@Anonymous 
This is exactly what it does. [Sales] is actally a measure [Sales] = SUM ( Sales[Sales] )
Alternatively you can use the fllowing:

MAX Sales = 
MAXX ( 
    VALUES ( 'Date'[Year] ),
    SUM ( Sales[Sales] )
)
MAX Sales Year = 
TOPN ( 1, 
    VALUES ( 'Date'[Year] ),
    SUM ( Sales[Sales] ),
    DESC 
)

 

Of course [Sales] can be SUM ( Sales[Sales] )

Anonymous
Not applicable

No, it's not showing the value. A table of multiple values was supplied where a single value was expected.

 

Hi @Anonymous 
Please try this

MAX Sales = 
MAXX ( 
    VALUES ( 'Date'[Year] ),
    CALCULATE ( SUM ( Sales[Sales] ) )
)
MAX Sales Year = 
TOPN ( 1, 
    VALUES ( 'Date'[Year] ),
    CALCULATE ( SUM ( Sales[Sales] ) ),
    DESC 
)

@Anonymous please try if that works for you. You need two measures:

 

 

 

Max Sales = 
Maxx ( values (Table[Year]), CALCULATE(sum(Table[Sales])))

 

 

 

 

 

MaxYear = 
var MaxSales= Maxx ( values (Tabele[Year]), CALCULATE(sum(Table[Sales])))
return 

CALCULATE(max( Table[Year]), filter ( values (Table[Year]), CALCULATE(sum(Table[Sales])= MaxSales)))

 

 

 

Hope that helps.

Best. 

Anonymous
Not applicable

Thank you .. this works

If you want to use TOPN -Function, this might work:

Maxx(TOPN ( 1, 
    VALUES ( Table[Year] ),
    calculate(SUM ( Table[Sales] )),
    DESC 
),Table[Year])

Can please send sample file with demo data?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.