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.
Hello,
I have a report with company sales. I want to get the average daily sales by dividing the total month sales by the number of working days. For example, January might have 20 working days, February 19, March 21.
I am thinking about using a DAX formula with "IF": Example> If month=January, then sales/20, else if month=February, then sales/19.... and so on until December.
Is there a faster way to do it?
Thank you for the help,
JALV
Solved! Go to Solution.
@Andvil , You can have
Work Day = if(WEEKDAY([Date],2)>=6,0,1)
In your calendar and sum it up for every month
Avg MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))/ CALCULATE(SUM('Date'[Work Day]),DATESMTD('Date'[Date]))
@Andvil , You can have
Work Day = if(WEEKDAY([Date],2)>=6,0,1)
In your calendar and sum it up for every month
Avg MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))/ CALCULATE(SUM('Date'[Work Day]),DATESMTD('Date'[Date]))
Basically you need to count the working days for each month. I would recommend you create a flag column to identify working days. And then use the column to find the total workings for respective month.
flag column = IF(WEEKDAY([Date])<>6 && WEEKDAY([Date],2)<>7,1)
Total working days Column = CALCULATE(SUM('Table'[flag]),ALLEXCEPT('Table','Table'[Date].[MonthNo]))
Result = Sales/Total working days
IF you need measure:
Total working days measure = CALCULATE(SUM('Table'[flag]),FILTER(ALL('Table'),[Date].[MonthNo]=MAX([Date].[MonthNo])))
Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hey @Andvil ,
please allow me to direct your attention to this article: https://www.daxpatterns.com/time-patterns/
This article covers almost everything necessary to create powerful time based calculations using DAX.
These kind of calculations become much more simple, if a dedicated calendar table is used to connect to the date columns in your fact tables.
Hopefully, this provides some additional ideas to tackle your challenges.
Regards,
Tom
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
95 | |
80 | |
68 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |