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 need to calculate the YTD value excluding the current month. I have the following information in a data table with a Month column. I added the Month_Number column using Switch. I now need to Divide the Sum of the EAC column by the Sum of the Revenue EAC column for the last one month given that we are in Feb. If we were in June, the sum would be all the past months excluding June. How do I do this?
Thank you for any suggestions.
Yoshi
Solved! Go to Solution.
Hi,
You may download my PBI file from here.
Hope this helps.
thanks @Ashish_Mathur @danextian @amitchandak @stretcharm for all your help.
I was able to solve this using @Ashish_Mathur solution.
I also found a similar solution here which also worked - https://community.powerbi.com/t5/Desktop/TotalYTD-to-Last-Month/m-p/692437
Correct Formula =
VAR pre =
CALCULATE (
MAX ( 'CalendarAuto'[Date] ),
FILTER ( 'CalendarAuto', DATEDIFF ( 'CalendarAuto'[Date], TODAY (), MONTH ) = 1 )
)
RETURN
CALCULATE(
SUM(Sheet1[EAC]),
FILTER(
Sheet1,
YEAR(Sheet1[Custom Date]) = YEAR(pre)
&& Sheet1[Custom Date] <= pre
)
)
The idea of using a separate Calendar table is a good one and one that I will use in the future I'm sure. Thanks @danextian for the tip.
Thanks again.
Yoshi
In case you have the date you can use time intelligence using date table
If you have a month then you convert into the date
date = date(table[year],date[month],1)
Then try like
YTD Sales month back = CALCULATE([Sum Sales],DATESYTD(ENDOFMONTH(DATEADD('Date'[Date Filer],-1,MONTH))))
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/
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin
You can get with the month number, but that will require all to be used. So move month and year to another table and join with this.
Till last month =
var _max = maxx(Month,Month[Month No]) -1
Var _maxYear = maxx(Month, Month[year])
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),fiter(all(Month),Month[Month]= _max && Month[Year]=_maxYear ))
Hello All
Thanks for the suggestions.
I have added two columns to my data table based on the above suggestions.
Custom Month Number = SWITCH('Zinfra ADPR Forecast'[Month], "JAN", 1, "FEB", 2, "MAR", 3, "APR", 4, "MAY", 5, "JUN", 6, "JUL", 7, "AUG", 8, "SEP", 9, "OCT", 10, "NOV", 11, "DEC", 12)
Custom Date Created to Calculate YTD = DATE(2020, 'Table'[Custom Month Number], 1)
I then get this in my data table.
Now I can calculate the TotalYTD using the formula below but it doesn't give me the correct result.
YTD = TOTALYTD(SUM('Table'[EAC]), 'Table'[Custom Date Created to Calculate YTD].[Date])
I want the value for all past months excluding the current month.
Thanks again.
Hi @Yoshimitsu411 ,
Try this:
YTD Last Month =
CALCULATE (
[Measure],
//YTD before the earliest date in the currently selected month
FILTER (
DATESYTD ( Table[Date] ),
Table[Date] < MIN ( Table[Date] )
)
)
Proud to be a Super User!
Thanks.
I tried your formula and I get (Blank)
Measure = CALCULATE(SUM(Sheet1[EAC]), FILTER(DATESYTD(Sheet1[Custom Date]), Sheet1[Custom Date] < MIN(Sheet1[Custom Date])))
Hi @Yoshimitsu411 ,
Please modify your formula to this:
Measure =
CALCULATE (
SUM ( Sheet1[EAC] ),
FILTER (
DATESYTD ( Sheet1[Custom Date] ),
Sheet1[Custom Date] < MIN ( Sheet1[Custom Date] ),
ALL(Sheet1[Custom Date], Sheet1[Filter Column2], Sheet1[Filter Column3])
)
)
Replace the filter columns with the date date/month columns you are going to use in the slicer.
Note: It is advisable to use an external Dates table. It will make your formula simpler.
Proud to be a Super User!
Thanks @danextian
I tried your formula and get the error - Too many arguments were passed to the FILTER function. The maximum argument count for the function is 2.
Use date dimension, As suggested in my last post and move month a back
YTD = TOTALYTD(SUM('Table'[EAC]), dateadd(Date[Date],-1,Month))
Thanks for your reply.
The formula makes sense unfortunately it is giving me the wrong value.
Here is some sample data.
Asset | Partner Project ID | Project Name | JAN EAC | FEB EAC | MAR EAC | APR EAC | MAY EAC | JUN EAC | JUL EAC | AUG EAC | SEP EAC | OCT EAC | NOV EAC | DEC EAC |
Contoso | CON-TOSO-001 | Lorem ipsum dolor sit amet | 1 | 2 | 3 | |||||||||
Contoso | CON-TOSO-002 | consectetur adipiscing elit. Donec rhoncus | 2 | 3 | 4 | |||||||||
Contoso | CON-TOSO-003 | arius diam consequat a. Maecenas eget | 3 | 4 | 5 | |||||||||
Contoso | CON-TOSO-004 | attis ex vestibulum in. Nulla ipsum velit | 4 | 5 | 6 | |||||||||
Contoso | CON-TOSO-005 | t tellus eget facilisis. Fusce posuere maximus leo | 5 | 6 | 7 | |||||||||
Contoso | CON-TOSO-006 | sapien sodales purus, at ornare odio | 6 | 7 | 8 | |||||||||
Contoso | CON-TOSO-007 | am laoreet pellentesque condimentum. Cras ac pellentesque odio | 7 | 8 | 9 | |||||||||
Contoso | CON-TOSO-008 | auris sapien sodales purus, at ornare | 8 | 9 | 10 | |||||||||
Contoso | CON-TOSO-009 | olutpat ac dignissim eget, dictum vitae magna. Duis et metus | 9 | 10 | 11 | |||||||||
Contoso | CON-TOSO-010 | placerat tellus eget facilisis | 10 | 11 | 12 | |||||||||
When I use your formula below, I get 120 which is the sum of JAN EAC and FEB EAC. What I want is 55 which is the sum of only JAN EAC because we are in the month of Feb. If we were in March then I would want to see 120 and so on.
Measure Past Months YTD = TOTALYTD(SUM(Sheet1[EAC]),DATEADD(Sheet1[Custom Date], -1, MONTH))
Here is my data table.
Thanks.
Hi,
You may download my PBI file from here.
Hope this helps.
thanks @Ashish_Mathur @danextian @amitchandak @stretcharm for all your help.
I was able to solve this using @Ashish_Mathur solution.
I also found a similar solution here which also worked - https://community.powerbi.com/t5/Desktop/TotalYTD-to-Last-Month/m-p/692437
Correct Formula =
VAR pre =
CALCULATE (
MAX ( 'CalendarAuto'[Date] ),
FILTER ( 'CalendarAuto', DATEDIFF ( 'CalendarAuto'[Date], TODAY (), MONTH ) = 1 )
)
RETURN
CALCULATE(
SUM(Sheet1[EAC]),
FILTER(
Sheet1,
YEAR(Sheet1[Custom Date]) = YEAR(pre)
&& Sheet1[Custom Date] <= pre
)
)
The idea of using a separate Calendar table is a good one and one that I will use in the future I'm sure. Thanks @danextian for the tip.
Thanks again.
Yoshi
You are welcome.
I would use PowerQuery/M to create a date field from the Month.
I do that using the Add column from example in this video
https://www.youtube.com/watch?v=t1WLdABqZeQ
Once you have a date you can do YTD calcs easily.
Curbal has a video explaining YTD here.
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 |
---|---|
114 | |
99 | |
83 | |
70 | |
60 |
User | Count |
---|---|
150 | |
115 | |
104 | |
89 | |
65 |