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
GiorgiPBI
New Member

Filtering YTD & YTD previous year with column chart

Hello,

 

stuck in this solution. 

I have simple sales table,

GiorgiPBI_0-1681240380429.png

 

in dashboard I have these visuals

GiorgiPBI_1-1681240472833.png

 

I want to have values by last date (march 2023) when nothing is selected , but YTD PY is showing the sum of whole previous year 12 and it should be 3. Also I want to filter right visual with column chart (if I click on february second visual should show  YTD 2 and YTD PY also 2. and so on) hope you understand the task.
here's PBIX file https://1drv.ms/u/s!Aucu3BmZNQw-qZV1Vuayls4KBsNEzw?e=5Iaekq

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@GiorgiPBI , Try if this formula can help, you can use the max date from table/fact in place of today 

 

YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LYTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = Date(Year(_max1)-1, Month(_max1), Day(_max1))
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@GiorgiPBI , Try if this formula can help, you can use the max date from table/fact in place of today 

 

YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LYTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = Date(Year(_max1)-1, Month(_max1), Day(_max1))
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

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.