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
Thoms
Frequent Visitor

sum and group with max results per day

Hi,

 

Friends, I need help with DAX  formula.

 

What i have :

cityproduct #datepcs
Beijing123544January 01 20191
Beijing123544January 01 201910
Beijing123544January 02 201915
Beijing123544January 02 20192
Shanghai123544January 01 20193
Shanghai123544January 01 201912
Shanghai123544January 02 201912

 

 

 

What i need is to make a measure which show only maximum results per day group by city, date and product pcs.

like this:

 

cityproductmonthsum and maximum result per day (pcs)
Beijing12354420190117
Shanghai12354420190115

 

Please help

 

1 ACCEPTED SOLUTION

hi, @Thoms 

If you want to keep [date] field in the visual, just adjust the formula as below:

Measure 2 = var _table=CALCULATETABLE(SUMMARIZE('Table','Table'[city],'Table'[product #],'Table'[Month],'Table'[date],"_pcs",SUM('Table'[pcs])),ALL('Table'[date])) return
MAXX(_table,[_pcs])

Result:

2.JPG

 

Best Regards,

Lin

Community Support Team _ Lin
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

12 REPLIES 12
v-lili6-msft
Community Support
Community Support

HI, @Thoms 

Just try this simple way as below:

Step1:

Create a month column for your date column

Month = YEAR('Table'[date])*100+MONTH('Table'[date])

Step2:

Use this formula to create a measure to get your requirement:

Measure = var _table=SUMMARIZE('Table','Table'[city],'Table'[product #],'Table'[Month],'Table'[date],"_pcs",SUM('Table'[pcs])) return
MAXX(_table,[_pcs])

Result:

1.JPG

And here is pbix file, please try it.

 

Best Regards,

Lin

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

If i add the days, table do not shows the total of the month

image.png

 

hi, @Thoms 

If you want to keep [date] field in the visual, just adjust the formula as below:

Measure 2 = var _table=CALCULATETABLE(SUMMARIZE('Table','Table'[city],'Table'[product #],'Table'[Month],'Table'[date],"_pcs",SUM('Table'[pcs])),ALL('Table'[date])) return
MAXX(_table,[_pcs])

Result:

2.JPG

 

Best Regards,

Lin

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

Dear,

 

Thanks a lot! works perfect!

hi, @Thoms 

You are welcome.  Smiley Very Happy

please accept the reply as solution, that way, other community members will easily find the solution when they get same issue.

 

best Regards,

lin

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

Hi,

 

Thankx for feedback! but how about if i need the column in the table, not measure?

danno
Resolver V
Resolver V

If you want to create a new table in power bi to summarise your data you can use the Modeling ribbon > New Table option and enter the following DAX
Sales Summary = SUMMARIZECOLUMNS(‘Product Sales’, [city], [product], “month”, FORMAT([date], “YYYYMM”), “Total pcs”, SUM[pcs], “Max pcs”, MAX[pcs]).
Thoms
Frequent Visitor

Danno thanks,

 

Sorry, i might have put it purly. 

Acctually ill be fine with a measure which will make a sum of sales of particular product per day and find max of those sales among days, to find when this product was selling better.

If you need help with measures let me know, otherwise please mark as solution

Thoms
Frequent Visitor

Yes, i need a measure. 

You need a column for the Month (if you dont already have a separate calendar table), that will alow you to group by month in the format you require.   The simple measures for max and total can be created as : Total pcs =  SUM([pcs]) and Max pcs = MAX([pcs]) and providing that you split the result by month you will see the results in your table / matrix on the report. 

Thoms
Frequent Visitor

Ok, ill try to explain in other way.

 

How do i add a new column in table (sumup per day and max in month by prod and city)?

 

cityproduct #datepcssumup per daymax in month by product and city
Beijing123544January 01 201911117
Beijing123544January 01 2019101117
Beijing123544January 02 2019151717
Beijing123544January 02 201921717
Shanghai123544January 01 201931515
Shanghai123544January 01 2019121515
Shanghai123544January 02 2019121215

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.