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
gdecome
Helper III
Helper III

Summarize sales by month including blanks and zeros

Hi all ... not sure if the best way to manage this request is using DAX or Power Query. Despite any option, how to do it.

I have a table with Sales_Rep names (first table below) and start dates. Another table with sales by Sales_Rep (second table) and I need to summarize by month (third table) including the volume for each sales rep. The summary should show blanks if the rep was not hired yet and 0 if there was no sales at that month (after hiring).

Any suggestion? Thanks in advance

 

Sales_Rep  Start_Date

Rep01   12/15/2019
Rep02   02/05/2020
Rep03   03/20/2020

 

Sales_Rep Sales_Date Units

Rep01   01/05/2020  5
Rep01   02/08/2020  3
Rep0103/04/2020  4
Rep0104/02/2020  7
Rep0105/01/2020  8
Rep0202/02/2020  2
Rep0203/03/2020  1
Rep0205/05/2020  2
Rep0304/04/2020  1
Rep0305/05/2020  2

 

 Jan-20Feb-20Mar-20Apr-20May-20
Rep01  53478
Rep02   2102
Rep03    012
1 ACCEPTED SOLUTION

This is great!

Thank you very much @v-diye-msft 

View solution in original post

11 REPLIES 11
v-diye-msft
Community Support
Community Support

Hi @gdecome 

 

kindly check my below results:

Measure = IF (
 MAX ( 'Table 2'[Column] ) < MAX ( 'Table (2)'[Column 2]),
 BLANK(),CALCULATE(
 IF (
 MAX ( 'Table 2'[Column] ) >= MAX ( 'Table (2)'[Sales_Date] ),
 MAX('Table (2)'[Units] ),
 IF (
 MAX ( 'Table 2'[Column] ) >= MAX ( 'Table (2)'[Column 2] )
 && ISBLANK ( MAX ( 'Table (2)'[Units] ) ),
 0
 )+0
 )
,USERELATIONSHIP('Table (2)'[Column],'Table 2'[Column]))+0)

04.PNG

Pbix attached.

 

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

This is great!

Thank you very much @v-diye-msft 

amitchandak
Super User
Super User

@gdecome , Join both tables on sales_rep. Join sales table with a date table having month year in that

and use this formula

 

sales = calculate(sum(sale[Units]), filter(Sales, sales[Sales_Date]>=related(Sales_Rep[Start_Date])))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Thank you @amitchandak , I will test and let you know

AllisonKennedy
Super User
Super User

@gdecome  Do you have a DimDate table?

https://allisonkennedycv.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

If you have the date table , then this will be relatively simple DAX query. 

 

One question - do we need to check the start date or can we assume they won't have any sales if they haven't started?

 

Please provide your table names and answers to my above questions and we can help you further. 

 

 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy , thank you for the quick reply.

About your questions

  • If you have the date table , then this will be relatively simple DAX query.
    • Yes, I have a Calendar table that could be used on this 
  • do we need to check the start date or can we assume they won't have any sales if they haven't started?
    • No, it should be blank anyway if they were not hire yet (at that month) considering they don´t have access to register.
    • If not started, shows blank in the month. If started but no sales in the month, shows zero.
  • Please provide your table names and answers to my above questions and we can help you further.
    • Calendar
    • Sales_Rep    (name and hiring date)
    • Sales            (name, sales date and units sold)

@gdecome  Ok, I see what you mean now, you will need to check start date to get blank vs 0.

 

Using the Calendar table in the Matrix, you should be able to apply this MEASURE:

 

Total Units = IF(MIN(Sales_Rep[StartDate])>=MIN(Calendar[Date]),0+ SUM(Sales[Units]))


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy it didn´t work yet ... it is showing just months related to Start_Date despite the Total Column with the right values (measure is similar to the one provided by @amitchandak too)

Total Units 2:=IF(MIN(Sales_Rep[Start_Date])>=MIN(Calendar[Date]),0+SUM(Sales_Units[Units]))

 

Obs: Relationships

Calendar / Sales_Rep is 1:1 Direction=Both

Calendar / Sales_Units is 1:n Direction=Single

 

Name    Dec-19  Feb-20   Mar-20  Total 

Rep01      0        3         4       27 
Rep02   0215
Rep03   0003

@gdecome , please find the attached file after signature, I am getting same result as first table

 

Thanks @amitchandak , I was better testing you formula and get the same result as yours.

Numbers are fine but one thing still missing is the "zero" after hiring date. For example, Rep02 should show "0" in Apr-20 as well as Rep03 should show 0 inMar-20 that is hiring date but no sales in that month.

In other words, show blank if not hired yet but show zero if hired but no sales for that period.

Great, thank you @AllisonKennedy  ... I will test and let you know.

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.