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
Anonymous
Not applicable

Create Measure Indicator to show "1" for all dates from start of the year till the selected date

Hello,

 

I want to create a measure that should give me an indicator "1" from the start of the year until the selected date.

 

For example, in the date filter if I selected 2/1/2020 then I should get an indicator "1" for 1/1/2020 and 2/1/2020 and "0" for all the other dates.

 

Below is the sample screenshot

 

 
 

Date.PNG

1 ACCEPTED SOLUTION

OK @Anonymous here are the issues that I see with this approach. You have a Date dimension that is connected to all of your tables. You can select a range of these and they will presumably show up in a table visualization. So far so good.

 

Now the question is, what Date are you displaying in your table visualization? Because if it is the Date from the Dimension table, there is a problem. Once you introduce your measure into that visualization. If you use SELECTEDVALUE or MAX to retrieve the Date, it will retrieve the date within the context of your table visualization, as in the date in the current row. This is not what you want, you want the date that is the maximum date within the slicer. So, what I believe will fix your problem in this case is to use ALLSELECTED:

 

Indicator = 
  VAR __SelectedDate = MAXX(ALLSELECTED('Calendar'[Date]),[Date])
  VAR __Date = MAX('Table'[Date])
  VAR __StartOfYear = DATE(YEAR(__SelectedDate),1,1)
  VAR __EndOfYear = DATE(YEAR(__SelectedDate),12,31)
RETURN
  IF(__Date >= __StartOfYear && __Date <= __EndOfYear,1,0)

 

However, if this is not the case there is likely a different solution. I updated the PBIX and attached it to be more representative of your model. Now there is a relationship between the tables. 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

10 REPLIES 10

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.

Top Solution Authors