cancel
Showing results for
Did you mean:  Helper II

## Maximum sales of a of a specific month within a specific year

I have created a measre named Total Sales. In the Dimdate table, there are Month, and Calender Year columns. Now I want to write a measure, Maximum sales of January 2011. I tried to solve it many ways but nothing works as I cannot organize the algorithm to solve it. How to do that?

2 ACCEPTED SOLUTIONS  Community Champion

This shalk give you the sales amount durinf Jan 2011 at the date that scored the highest sales

``````Maximum sales of January 2011 =
MAXX (
SUMMARIZE (
CALCULATETABLE (
SalesTableName,
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
),
DimDate[Date],
"@Amount", [Total Sales]
),
[@Amount]
)``````  Resolver III

One of them will be the fastest:

``````Maximum sales of January 2011 =
MAXX (
SUMMARIZE (
CALCULATETABLE (
SalesTableName,
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
),
DimDate[Date]
),
[Total Sales]
)

-- or

Maximum sales of January 2011 =
CALCULATE(
MAXX (
SUMMARIZE (
SalesTableName,
DimDate[Date]
),
[Total Sales]
),
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
)

-- or
Maximum sales of January 2011 =
CALCULATE(
MAXX (
// on condition that SalesTableName[Date]
// is connected to your DimDate table
// on Date.
VALUES ( SalesTableName[Date] ),
[Total Sales]
),
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
)``````

By the way, SUMMARIZE should never be used for calculations, only for grouping, since this function has a bug that Microsoft have refused to fix. Alberto Ferrari has an article about it.

18 REPLIES 18  Community Champion
``````Maximum sales of January 2011 =
MAXX (
CALCULATETABLE ( Sales, DimTable[Month] = 1, DimTable[Year] = 2011 ),
Sales[Sales]
)``````  Helper II

Hi, I have a measure Total sales. So calculatetable woun't take a measure. Could you please give me another solution that take a measure?  Community Champion

How does your visual look like?  Helper II

The function is no working. I tried with MAX, MAXX, and Calculate but getting red underline.  Community Champion

I mean what are you slicing by? What visual are you using? Table, matrix, chart or just a card visual? What columns are involved in that visual? What exactly is the code that you have used but recieved error?  Helper II

Oh, okay. It's for card visual.  This is how I tried.

MAX sales JAN 2011 =
MAX(CALCULATE([Total Sales],
DimDate[CalendarYear] = 2011 || DimDate[Month] = "January"
)
)  Community Champion

@Alex_Hasan
Here is the code with clarification

``````Maximum sales of January 2011 =
MAXX (
CALCULATETABLE (
SalesTableName,
DimTable[Month] = "January",
DimTable[CalendarYear] = 2011
),
SalesTableName[SalesAmountColumnName]
)``````

or

``````Maximum sales of January 2011 =
MAXX (
CALCULATETABLE (
SalesTableName,
DimTable[Month] = "January",
DimTable[CalendarYear] = 2011
),
[Total Sales]
)``````  Helper II

It's not showing correct value. And I repeat, I must use Total sales measure instead of sales table, not a single column from sales table.  Community Champion

can share a screeshot?  Helper II

This is the maximum sales of january 2011. When I tried with your code, this is what I got.   Resolver III

To be able to write the code you want one has to know the organization of your Sales table. Is every row a complete sale? If now, then which column identifies all the rows that belong to the same sale? You have to answer such question first to be able to write the desired formula.  Community Champion

What is the definition of maximum sales? By product, by customer, by date, by invoice number?  Helper II

This is the link. you will find the excercise in context transition page
https://1drv.ms/u/s!AtNgJBWI0wXOb5GOZf-anQJd3dc?e=6dgu3t  Helper II

By date.  Community Champion

This shalk give you the sales amount durinf Jan 2011 at the date that scored the highest sales

``````Maximum sales of January 2011 =
MAXX (
SUMMARIZE (
CALCULATETABLE (
SalesTableName,
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
),
DimDate[Date],
"@Amount", [Total Sales]
),
[@Amount]
)``````  Resolver III

One of them will be the fastest:

``````Maximum sales of January 2011 =
MAXX (
SUMMARIZE (
CALCULATETABLE (
SalesTableName,
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
),
DimDate[Date]
),
[Total Sales]
)

-- or

Maximum sales of January 2011 =
CALCULATE(
MAXX (
SUMMARIZE (
SalesTableName,
DimDate[Date]
),
[Total Sales]
),
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
)

-- or
Maximum sales of January 2011 =
CALCULATE(
MAXX (
// on condition that SalesTableName[Date]
// is connected to your DimDate table
// on Date.
VALUES ( SalesTableName[Date] ),
[Total Sales]
),
DimDate[Month] = "January",
DimDate[CalendarYear] = 2011
)``````

By the way, SUMMARIZE should never be used for calculations, only for grouping, since this function has a bug that Microsoft have refused to fix. Alberto Ferrari has an article about it.  Helper II

It worked ! Thank you. But I would like know why we used SUMMERIZE function? and why "@Amount" in that way? could you please elaborate, it seems a tough one?  Community Champion

This is not the code I provided. Please check with the same code Announcements The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform. #### Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison! #### The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022. Top Solution Authors
Top Kudoed Authors
Users online (1,531)