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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Alex_Hasan
Helper II
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

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]
)

View solution in original post

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.

View solution in original post

18 REPLIES 18
tamerj1
Super User
Super User

hi @Alex_Hasan 

Maximum sales of January 2011 =
MAXX (
    CALCULATETABLE ( Sales, DimTable[Month] = 1, DimTable[Year] = 2011 ),
    Sales[Sales]
)

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? 

tamerj1
Super User
Super User

@Alex_Hasan 

How does your visual look like?

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

@Alex_Hasan 

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?

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"
)
)

@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]
)

 

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.

can share a screeshot?

 

This is the maximum sales of january 2011. 

Capture1.JPG

 

When I tried with your code, this is what I got.

Capture2.JPG

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.

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

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

By date. 

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]
)

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.

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? 

This is not the code I provided. Please check with the same code

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors