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
Giavo
Helper III
Helper III

DAX: SELECTEDVALUE with Dates

Hello all,

 

INTRO:

i have a Relational model with 3 tables:

1)Project Milestones table containing Project Codes and 4 dates per each project (Date1, Date2, Date3, Date4)
2)Projects Table containing unique project codes

3)Locations table containing Locations and related Project codes

 

I have a rule in Project Milestones table in order to determine if a project is ACTIVE in a certain year and it is as follow:

Column:

Active in 2018 = IF((YEAR(Date 1)<=2018 || YEAR(Date 2)<=2018) &&
                                 (YEAR(Date 3)>= 2018 || YEAR(Date 4)>=2018)."Active"."Not Active")

 

This rule gives me all the ACTIVE Projects in 2018 displayed per Location.
PROBLEM:
I want the user to be able to select a YEAR himself in order to see all the active projects for the selected year; (not fixed 2018 anymore)

i tried this:
i have created a new Calendar table containing dates and applied this rule:

Active in X =
VAR SelectedYear=SELECTEDVALUE('Calendar'[Year])
RETURN 
IF((YEAR(Date 1)<=SelectedYear || YEAR(Date 2)<=SelectedYear) &&
                                 (YEAR(Date 3)>= SelectedYear || YEAR(Date 4)>=SelectedYear)."Active"."Not Active")

Apparently SelectedYear=SELECTEDVALUE('Calendar'[Year]) doesn't work properly. Do you know how can i improve this rule ?

2 ACCEPTED SOLUTIONS

@Giavo I am just looking for sample data not actual data, but anyway I guess you are looking for this..

 

Test122Count = 
VAR _SelectedYear = SELECTEDVALUE(_DimDate[Year])
VAR _Temp = FILTER(Test122,
((YEAR(Test122[Date1])<=_SelectedYear || YEAR(Test122[Date2])<=_SelectedYear) && (YEAR(Test122[Date3])>=_SelectedYear || YEAR(Test122[Date4])>=_SelectedYear)))
VAR _Temp1 = IF(COUNTROWS(_Temp)>0,1,0)
RETURN SUMX(_Temp,_Temp1)

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

Hi @Giavo,

 

I think the following formula should do what you expect, essentially it will count the rows on the 'Project Milestones' table where the conditions are met based on the selected value

 

Active in X =
VAR SelectedYear=SELECTEDVALUE('Calendar'[Year])
RETURN 
Calculate(CountRows('Project Milestones'), FILTER('Project Milestones', (YEAR(Date 1)<=SelectedYear || YEAR(Date 2)<=SelectedYear) &&
(YEAR(Date 3)>= SelectedYear || YEAR(Date 4)>=SelectedYear)))


I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


View solution in original post

12 REPLIES 12

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.