Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Row level calculation based on date selected

Hi,

 

  I have a table with a Original_Date field on each row. I will have a date slicer for user to pick the date. 

 

  I need to use a Matrix with Group, Tenant, Type in Rows and a new calculated field in Values. This new field will calculate Days_Outstanding (= User's Date - Original_Date). 

 

  The issue is that this calculation first needs to happen on each row and each Group+Tenant+Type is not unqiue, so I can't use User's Date - Max(Original_Date) in DAX. My idea is create a dynamic temp table that refreshes itself depend on User's Date but I don't know how.

 

  Here is an example in Excel: Col A-E are source data. Col F links to user's selected date so it's dynamic, then col G calculation will update. However I'm not sure how to implement something similar in Power BI using DAX.

 

Having problem to attach a pbix file, so I pasted the data here. Thank you!

IDGroupTenantTypeOriginal_Date
1ATenant A1Rent1/2/2018
2ATenant A1Rent1/3/2019
3ATenant A1Payment1/6/2021
4ATenant A2Rent4/26/2019
5ATenant A2Rent5/4/2018
6ATenant A2Payment4/30/2020
7BTenant B1Rent9/4/2019
8BTenant B1Payment12/12/2018
9BTenant B1Rent2/5/2020
10BTenant B2Rent2/12/2020
11BTenant B2Payment3/27/2018
12BTenant B2Rent4/14/2020
13CTenant C1Rent3/8/2018
14CTenant C1Rent10/16/2018
15CTenant C1Payment5/8/2019
16DTenant D1Rent10/30/2018
17DTenant D1Payment4/30/2020
18DTenant D2Rent7/30/2018
19DTenant D2Rent1/11/2019
20DTenant D2Payment3/5/2019

 

  • Anonymous 

    You cannot update a table from a slicer as the model is completed and loaded. To achieve your goal, you can create a measure based on the user's date selection:

    Days Outstanding = 
    var __dateselected = SELECTEDVALUE(Dates[Date]) return
    SUMX(
        Table3,
       DATEDIFF( __dateselected ,Table3[Original_Date],DAY )
    )

     

     

     

     


     

2 Replies

  • Anonymous 

    You cannot update a table from a slicer as the model is completed and loaded. To achieve your goal, you can create a measure based on the user's date selection:

    Days Outstanding = 
    var __dateselected = SELECTEDVALUE(Dates[Date]) return
    SUMX(
        Table3,
       DATEDIFF( __dateselected ,Table3[Original_Date],DAY )
    )

     

     

     

     


     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks a lot! It's working!