Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

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, @Anonymous 

 

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, @Anonymous 

 

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

@Anonymous , 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))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

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 @Anonymous,

 

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!



Anonymous
Not applicable

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.