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

Using selected value from one table in a calculation in another table

Hi,

I've been struggling with this task in pbi:

I have TABLE1 where I have START_DATE and END_DATE.

In TABLE2 I generated ALL_DATES for last 2 years till today.

 

I have a slicer with ALL_DATES where end user can select any date, based on that date I need to calculate something related to both START_DATE and END_DATE.

 

for example: I've selected 10-10-2022 and I would like to see the count of items from TABLE1 where:

START_DATE<ALL_DATES(selected) and END_DATE<=ALL_DATES(selected)

 

is it possible? I tried to get max of ALL_DATES but it gave me strange results (different value for each row in TABLE1).

 

btw, is it possible to create a parameter which can be used like a variable in filters or measures? 

I'm experienced in Tableau and if I had to do it in Tableau it would take me 2 minutes, now I got stuck.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table1:

vbinbinyumsft_0-1675736721986.png

Table2:

Table2 = CALENDAR(DATE(2022,01,01),DATE(2023,2,6))

vbinbinyumsft_1-1675736735522.png

2. create a measure with below dax formula

Measure =
VAR min_date =
    MINX ( 'Table2', [Date] )
VAR max_date =
    MAXX ( 'Table2', [Date] )
VAR tmp =
    FILTER ( ALL ( Table1 ), [Start Date] >= min_date && [End Date] <= max_date )
RETURN
    SUMX ( tmp, [Sales] )

3. add a slicer with Table2 field, add a card visual with measure

vbinbinyumsft_2-1675736853692.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

My preferred approach would be to create one row for each date between the start date and end date.  Then create a relationship between the Date column so create and the Date column of the Calendar Table.  To receive further help, share data (in a format the can be pasted in an MS Excel file).


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table1:

vbinbinyumsft_0-1675736721986.png

Table2:

Table2 = CALENDAR(DATE(2022,01,01),DATE(2023,2,6))

vbinbinyumsft_1-1675736735522.png

2. create a measure with below dax formula

Measure =
VAR min_date =
    MINX ( 'Table2', [Date] )
VAR max_date =
    MAXX ( 'Table2', [Date] )
VAR tmp =
    FILTER ( ALL ( Table1 ), [Start Date] >= min_date && [End Date] <= max_date )
RETURN
    SUMX ( tmp, [Sales] )

3. add a slicer with Table2 field, add a card visual with measure

vbinbinyumsft_2-1675736853692.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you! That's what I was looking for.

I was a bit weird to me why max/min doesn't work (should've used maxx/minx) and the way of applying Filter() wasn't intuitive. 

amitchandak
Super User
Super User

@Anonymous , You can get max and Min date like

 

//Date1 is independent Date table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = minx(allselected(Date1),Date1[Date])
return
calculate( sum(Table[Value]), filter('Table', 'Table'[Start Date] <=_max && 'Table'[End Date] >=_max))

 

 

Power BI Dax Measure- Allocate data between Range: https://youtu.be/O653vwLTUzM

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

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.