Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
YunJ
Post Prodigy
Post Prodigy

Table based on YTD/MTD

Hi 

 

I want to show table based on YTD/MTD filter. When choosing MTD, only show MTD month(at this situation would be 2020.04), when choosing YTD, show values for 2020.01~2020.04 at this situation. 

11.PNG

I wrote calculation like this, I cannot put this to the FILTERS pane to choose true/false...

Capture.PNGCapture2.PNG

Thanks

Yun

 
14 REPLIES 14
amitchandak
Super User
Super User

@YunJ , In case you have Date use Time Intelligence and date calendar.

 

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(Table[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd(Table[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd(Table[Date],-1,MONTH))))
last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd(Table[Date],-12,MONTH)))


YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((Table[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR(Table[Date])),"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd(Table[Date],-1,Year),"12/31"))

 

 

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/

 

You can create a date like.(Based on the format I can see)

 

Date = Date(Left([Month year],4),right([Month year],2),1)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hello @amitchandak 

 

For this pic, I'm wondering is my date slicer can be look like this right? rather than a range data(e.g. 202001~202004) or multiple choices(e.g. 202001,202002) right?

Capture.PNGCapture.PNG

@YunJ , Throughout Year and Month from a table of dates, you can use time intelligence. Even if you select year, month or date, etc. The last quote is your base.

@YunJ , As along as Year and Month coming from a date table, You can use time intelligence. Even if select year, month or date etc . The last date is your base.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks a lot @amitchandak 

 

I found I can only use Date as slicer rather than Year and Month to calculate YTD right?

Capture.PNG

Capture.PNG

 

Capture.PNG       Capture.PNG

 

Thanks for your patience.

Yun

Hi @YunJ ,

 

You used DATESYTD() function and it need a date parameter.

Your "Month" and "Year" columns are number type, so I think it results in the incorrect result. 

 

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

Thanks @v-eachen-msft 

So in my understanding. If I want to calculate YTD, the slicer I use must be Date format, Year(YEAR('Date[Date]'))/Month/Quarter which are created by Date will not work right?

 

 

Thanks for your reply. But I have many measures in the table. So I don't want to set MTD/YTD for per measure in its calculation... I prefer to set a month calculation like following to make a general calculation only for month like following.

Capture.PNG

@YunJ Can you share sample data and sample output.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak 

I find a way to download pbix file. Hope you can open it.

Link: https://pan.baidu.com/s/1AonoyNSxPxNKPM7XAg_E4Q

Code: k6qk

 

 

What I would like to do is for example,

when select year=2020, month=4, YTD/MTD=YTD, the table will show values for 2020.01~2020.04. 

when select year=2020, month=4, YTD/MTD=MTD, the table will show values for 2020.04. 

Hi @YunJ ,

 

I cannot download your file directly, it need a third-party software. Please upload your files to OneDrive for Business without any Confidential Information and share the link here.

 

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

@YunJ , Try this. Not accessed file yet

new Measure =
var _maxyr = Maxx(allselected('Date'),'Date'[Year])
var _maxmt = Maxx(allselected('Date'),'Date'[Month])
var _maxparam = Maxx(allselected('YTD_MTD'),'YTD_MTD'[YTD_MTD_PARAM])
return
if(_maxparam = "MTD" , calculate([Measure],filter(all('Date'),'Date'[Month]=_maxmt && 'Date'[Year] = _maxyr)),
calculate([Measure],filter(all('Date'),'Date'[Month]<=_maxmt && 'Date'[Year] = _maxyr)))

 

Also refer : https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi! I cannot attach as onedrive/dropbox. Could I send you via email?

Helpful resources

Announcements
Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.