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
readyraddy
Helper I
Helper I

DAX: Date filters for benchmark value

My data ranges from January 2020 to October 2020.

I am trying to display 2 different values based on my date slicer.

 

1st Visual = Calculated value based on date selected

2nd Visual (benchmark) = Calculated value based on the year of the date selected (eg. even if the date selected is from March to May, the value displayed should be from January to October)

 

Any way I can achieve this?

Thanks

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @readyraddy ,

According to your description, I created some data to show:

v-yangliu-msft_0-1606717617577.png

Here are the steps you can follow:

1. Create measure.

1st Visual = SUM('Table'[amount])
2nd Visual =
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),MONTH([Date])>=1&&MONTH([Date])<=10&&YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))))

2. Result.

v-yangliu-msft_1-1606717617582.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-yangliu-msft
Community Support
Community Support

Hi  @readyraddy ,

According to your description, I created some data to show:

v-yangliu-msft_0-1606717617577.png

Here are the steps you can follow:

1. Create measure.

1st Visual = SUM('Table'[amount])
2nd Visual =
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),MONTH([Date])>=1&&MONTH([Date])<=10&&YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))))

2. Result.

v-yangliu-msft_1-1606717617582.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

readyraddy
Helper I
Helper I

Noticed that using VAR in the measures will cause the value to filter despite the filtering statements.

readyraddy
Helper I
Helper I

I'm using this measure to get my YTD date.

How do I make use of this measure to obtain the Sales for that Year?

 

 

YTD_YEAR = YEAR(CALCULATE(MIN('Date'[Date]),ALLSELECTED('Date'[Date])))

 

 

 

amitchandak
Super User
Super User

@readyraddy , 12/31 end date year means 1/1 is the start of the year. If datesytd does not work try like

 

Measure =
var _max = maxx(allselected('Date') , 'Date'[Date])
var _min = minx(year(_max),1,1)
return
calculate(countrows('Table'), Filter(all('Date'), 'Date'[Date] >=_min && 'Date'[Date] <=_max ))

 

But make sure you are using date table and marked it as a date table.

I would like to try that measure by I'm getting an error here that says "Parameter is not the correct type."

var _min = minx(year(_max),1,1)

 

amitchandak
Super User
Super User

@readyraddy , With Date table you can use datesytd if date is selected from Date table

example
Within Range -SUM(Sales[Sales Amount]

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"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 :radacad sqlbi My Video Series Appreciate your Kudos.

 

 

Thanks for the reply. I would like to understand the DATESYTD portion.

What is the purpose of indicating "12/31"?

 

Also, I have tried the formula. It doesn't work and the "YTD Sales" still was still filtered.

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.