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
Niel
Regular Visitor

Calculate max of a month, per day.

Let's say I have a table like the below, so that the granularity is Datekey & ProductID.

Now I would like to get the highest sales per day, of the month.

The result for month 201807 should be 22 (that's the sales of 20180701) 

That's pretty straight forward to calculate when there are no filters by using

 

SalesDaily = CALCULATE(
sum(factRevenue[Sales])|FILTER(
factRevenue|(factRevenue[DateKey]=EARLIER(factRevenue[DateKey]))
))

However if I were to then filter on ProductID = 1 for example the above wouldn't work, since this calculation creates a column on the dataset (which happens before the interactions happen, so no filters are applied).

 

Hope that makes sense?

Capture.PNG

1 ACCEPTED SOLUTION

Hi Niel,

 

It should be a measure in your scenario. Please try the demo in the attachment.

Measure =
MAXX (
    SUMMARIZE ( 'Table1', 'Table1'[Datekey], "total", SUM ( Table1[Sales] ) ),
    [total]
)

Calculate_max_of_a_month_per_day

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
MFelix
Super User
Super User

Hi @Niel,

 

Not sure if I understand your question, the formula you present is for a calculated column or measure?

 

If you want to calculate the maximum sales per day you just need to make the measure 

Sales Daily = SUM(Table[Sales])

Measure are calculated on context so if you only add the day it wil give you 22 for 20180701 and so on, when adding slicers or filter to your visual or report this will affect the context of your measure and calculated it according to that data so you will get 10  when you select the Product 1.

 

Can you share some more insights on what is your doubt?

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Niel
Regular Visitor

Hi, 

Thanks for the reply. Apologies if I wasn't clear.

The function I gave is for a column.

As I mentioned, I would like to get the highest sales per day, of the month.

 

So the highest sales day in July would be 22

When filtering on productid = 1, the highest day for the month would be 14.

These are the numbers to be shown in the table when grouping by yearmonth instead of by date.

Hi @Niel,

 

The calculated column won't response to the slicer in the report. So if the value is 22, it will always be 22 unless the data source changes. Did you try the @MFelix's solution? Create a measure instead.

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Dale,

No, MFelix didn't read my question correctly, so he's not answering my question at all.

I'll just accept this as another Power BI limitation and just create a seperate dataset to calculate this.

 

Thanks,

Niel

Hi @Niel,

 

In Power BI as a good practice you should create measures instead of calculated columns.

 

Looking at your needs, if you make a calculated column you will have issues on slicing the information. Becasue if you calculate the max of sales for a month your column will be with a single value per month, in your example 22, if you want to add the product then the value will be 14, and you only be abble to get 1 product, adding variations of this to the calculated colum you will get the same values as in column sales.

 

This is a perfect case to create a measure since based on context the result you need is different, try the @v-jiascu-msft solution and tell if it works.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi Niel,

 

It should be a measure in your scenario. Please try the demo in the attachment.

Measure =
MAXX (
    SUMMARIZE ( 'Table1', 'Table1'[Datekey], "total", SUM ( Table1[Sales] ) ),
    [total]
)

Calculate_max_of_a_month_per_day

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Awesome, thank you so much. Works perfectly

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.