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.
Hi,
How can we build a Dax to calculate sales from the current date to the beginning of the month and compare it with a similar date range from the prior month? Also, the date has to be dynamic.
For example, 01-June-2020 and the current date is 25-June-2020.
and we need to compare it with the prior month for the same date range 01-May-2020 and 25-May-2020.
Moreover, if we run it again on the 28-June, the current date should be 28-June and 28-may.
please let me know and thanks for helping
Solved! Go to Solution.
Try this measure:
Hi, @mannymann
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may try the following measures.
CurrentMonthSales =
var _currentdate = TODAY()
var _startdate = DATE(YEAR(_currentdate),MONTH(_currentdate),1)
return
CALCULATE(
SUM('Table'[Sales]),
FILTER(
ALL('Table'),
'Table'[Date]>=_startdate&&
'Table'[Date]<=_currentdate
)
)
LastMonthSales =
var _day = DAY(TODAY())
var _startdate = EOMONTH(TODAY(),-2)+1
var _enddate = DATE(YEAR(_startdate),MONTH(_startdate),_day)
return
CALCULATE(
SUM('Table'[Sales]),
FILTER(
ALL('Table'),
'Table'[Date]>=_startdate&&
'Table'[Date]<=_enddate
)
)
Today is 7/1/2020. Here is the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @mannymann ,
If you have a date calendar, you can use the date intel functions.
Check this link: https://docs.microsoft.com/en-us/dax/sameperiodlastyear-function-dax
I'm looking for the same period last month comparison.
So, sameperiodlastyear function doesn't help.
Try this measure:
Hi @mannymann ,
I believe it's possible to do it. Give us more details about how you would like to automatize it. For example, get the current month and last and expand them with those day name/times ?
For example, we want the stats or number for the current and the prior month where the date range as follows:
Let say today is July-07-2020.
We are looking for our Start date to be the July-01-2020 (1st default) and end to be July-07-2020 (dynamically picked).
Now, we want the number/stats for last month where the date range should be June-01-2020 to June-07-2020.
Scenario 2: If it was march 30.
Then we want to compare the stats for last month within the date range from 1st to 30. Whereas February doesn't have 30 days, so it should pic the last date in February.
So, we would like the date range to be automatic. Where 1st of the month can be static but the last day(today) should be automatically selected to do the realtime comparison for that many number or dates.
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 |
---|---|
102 | |
53 | |
21 | |
12 | |
12 |