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

YTD Values to be shown as 1 in a calculated column all other values as 2 based on date column

Hi Experts

 

Need a calcuated column measure which returns a value of 1 if the date falls with the YTD parameter and all future dates as 2. I have a date column in my FACT Table.

1 ACCEPTED SOLUTION

Hi, @Anonymous 
In amitchandak's formula, you need to replace 'and' with '&&'.
The formula should be something like as below: 

a new column =
VAR _max =
    TODAY ()
VAR _min =
    DATE ( YEAR ( _max ), 1, 1 )
RETURN
    SWITCH ( TRUE (), [Date] > _max, 2, [Date] <= _max && [Date] >= _min, 1, 0 )

 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous ,

a new column =

var _max = today()

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

return

Switch(True(),

[Date] >_max, 2,

[Date] <=_max and [Date] >=_min , 1,

0)

Anonymous
Not applicable

Hi Amit - Getting and error on this line of DAX "var _min = date(year(_max),1,1)"

Hi, @Anonymous 
In amitchandak's formula, you need to replace 'and' with '&&'.
The formula should be something like as below: 

a new column =
VAR _max =
    TODAY ()
VAR _min =
    DATE ( YEAR ( _max ), 1, 1 )
RETURN
    SWITCH ( TRUE (), [Date] > _max, 2, [Date] <= _max && [Date] >= _min, 1, 0 )

 

 

Best Regards,
Community Support Team _ Eason

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.