Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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?
Solved! Go to Solution.
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.
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?
The function is no working. I tried with MAX, MAXX, and Calculate but getting red underline.
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.
@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.
When I tried with your code, this is what I got.
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
User | Count |
---|---|
41 | |
27 | |
23 | |
19 | |
16 |
User | Count |
---|---|
55 | |
35 | |
21 | |
18 | |
15 |