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

Calculate a date field based on a filter

jayPBI23_0-1595343920145.png

 

If a user selects this Settled Date range,

 

I want the CR001_Reporting_Period_Start_Date to match '6/1/2020' &

CR001_Reporting_Period_Start_Date to match '6/30/2020' 

 

So pretty much dynaically update the field to whatever the user selected in the filter. Is this possible?

 

Thanks for any help in advance!

 

Jay

 

 

 

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

Hi, @jayPBI23 

 

Based on your description, I created datat to reproduce your scenario. The pbix file is attached in the end.

 

Table:

e1.png

 

Calendar(a calculated table):

Calendar = CALENDAR(DATE(2020,6,1),DATE(2020,12,31))

 

There is no relationship between two tables. You may create two measures as below.

CR001_Reporting_Period_Start_Date = 
CALCULATE(
    MIN('Calendar'[Settled Date]),
    ALLSELECTED('Calendar'[Settled Date])
)

CR001_Reporting_Period_End_Date = 
CALCULATE(
    MAX('Calendar'[Settled Date]),
    ALLSELECTED('Calendar'[Settled Date])
)

 

Result:

e2.png

 

Best Regards

Allan

 

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

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hi, @jayPBI23 

 

Based on your description, I created datat to reproduce your scenario. The pbix file is attached in the end.

 

Table:

e1.png

 

Calendar(a calculated table):

Calendar = CALENDAR(DATE(2020,6,1),DATE(2020,12,31))

 

There is no relationship between two tables. You may create two measures as below.

CR001_Reporting_Period_Start_Date = 
CALCULATE(
    MIN('Calendar'[Settled Date]),
    ALLSELECTED('Calendar'[Settled Date])
)

CR001_Reporting_Period_End_Date = 
CALCULATE(
    MAX('Calendar'[Settled Date]),
    ALLSELECTED('Calendar'[Settled Date])
)

 

Result:

e2.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

@jayPBI23 , Try like

measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return calculate(sum(Table[column]), filter(Allselected(Table),Table[CR001_Reporting_Period_Start_Date]=_min && Table[CR001_Reporting_Period_Start_Date]=_max))

measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return calculate(sum(Table[column]), all(Table[Settled Date]),filter(Table,Table[CR001_Reporting_Period_Start_Date]=_min && Table[CR001_Reporting_Period_Start_Date]=_max))

Hi Amit. 

 

I don't use Dax as much. Trying to use your code keeps erroring out for me. Here are some details. 

 

Table = 'Query1'

Date slicer field = 'SettledDate' 

CR0001_Reporting_Period_start_Date should be '6-1-2020' based on the settled date filter

CR0002_Reporting_Period_End_Date should be '6-30-2020' based on the settled date filter

 

What exactly does the measure need to be?

 

Thanks a bunch!

 

Jay

 

camargos88
Community Champion
Community Champion

Hi @jayPBI23,

 

You are gonna need 2 measures here, getting min and max of the selected date, something like:

 

Measure1 = 

VAR _dtStart = MINX(TABLE[DATE], [DATE])

RETURN CALCULATE(SUM(TABLE[VALUES]), FILTER(ALL(TABLE([DATE]), [DATE] = _dt_Start))

 

Measure1 = 

VAR _dtEnd= MAXX(TABLE[DATE], [DATE])

RETURN CALCULATE(SUM(TABLE[VALUES]), FILTER(ALL(TABLE([DATE]), [DATE] = _dtEnd))



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

Proud to be a Super User!



I don't use Dax as much. Trying to use your code keeps erroring out for me. Here are some details. 

 

Table = 'Query1'

Date slicer field = 'SettledDate' 

CR0001_Reporting_Period_start_Date should be '6-1-2020' based on the settled date filter

CR0002_Reporting_Period_End_Date should be '6-30-2020' based on the settled date filter

 

What exactly does the measure need to be?

 

Thanks a bunch!

 

Jay

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.