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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
morganrosser
Regular Visitor

How to use a value from a date field as my filter

I have data in 2 tables
analytic_metrics
assets

 

These tables are related using a serial number. 


The asset table houses a "last replaced date."

 

I'd like to run a report out of my analytic_metrics table that runs a sum of shots since the "last replaced date" in the asset table. 

Am I able to use this last replaced date value as my filter? 

 

Thanks

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

Hi @morganrosser ,

Please try below steps:

Create a measure with below dax formula:

Measure =
VAR cur_id =
    SELECTEDVALUE ( Analytic_metrics[sim_id] )
VAR _date =
    CALCULATE (
        MAX ( Asset[Date_Replaced_hitting_Strip] ),
        Asset[SerialNumber] = cur_id
    )
VAR tmp =
    FILTER ( ALL ( Analytic_metrics ), [sim_id] = cur_id && [date] > _date )
RETURN
    IF ( ISBLANK ( _date ), 0, SUMX ( tmp, [shots] ) )

Add a table visual with Analytic_metrics[sim_id] and measure

vbinbinyumsft_0-1666684910878.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
v-binbinyu-msft
Community Support
Community Support

Hi @morganrosser ,

Please try below steps:

Create a measure with below dax formula:

Measure =
VAR cur_id =
    SELECTEDVALUE ( Analytic_metrics[sim_id] )
VAR _date =
    CALCULATE (
        MAX ( Asset[Date_Replaced_hitting_Strip] ),
        Asset[SerialNumber] = cur_id
    )
VAR tmp =
    FILTER ( ALL ( Analytic_metrics ), [sim_id] = cur_id && [date] > _date )
RETURN
    IF ( ISBLANK ( _date ), 0, SUMX ( tmp, [shots] ) )

Add a table visual with Analytic_metrics[sim_id] and measure

vbinbinyumsft_0-1666684910878.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.

Hi, @v-binbinyu-msft ,

Thanks for the reply. 

Apologies for the delay, I had some travel mixed in that made it tough to respond. 

I was able to use your dax formula to create the measure. But I uncovered an issue in field formatting in my tables. The sim_id is an integer while the sim ID is text/number. 

morganrosser_0-1667843362277.png

 

Should I create a measure that converts the sim_id to a number or do I build that into the provided dax formula? 

 

Thanks

 

lbendlin
Super User
Super User

yes, that is possible.

 

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Hi, thanks for the response!

Sample Data

Table 1: analytic_metrics

sim_id       date              shots           location_id    
2069348210/20/2022

100

2
2069348210/18/20222502
7032100510/20/20227579
2069348210/10/2022502

 

Table 2: Asset

SerialNumberDate_Replaced_hitting_Strip
2069348210/17/2022

 

 

I have the above two tables where 

analytic.sim_id = Asset.SerialNumber

 

I want to create a table where I can show shots on sim_id/SerialNumber = 20693482 since the Date_Replaced_Hitting_Strip (10/17/2022). A table format would be perfect:

 

Filters

Sim_id = 20693482 (I'm fine hard coding this filter as we need)

analytic_metrics.Date = Asset.Date_Replaced_Hitting_Strip 

sim_idsum of shots
20693482350

 

 

Thanks!

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.