Forum Discussion
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!
| ID | Group | Tenant | Type | Original_Date |
| 1 | A | Tenant A1 | Rent | 1/2/2018 |
| 2 | A | Tenant A1 | Rent | 1/3/2019 |
| 3 | A | Tenant A1 | Payment | 1/6/2021 |
| 4 | A | Tenant A2 | Rent | 4/26/2019 |
| 5 | A | Tenant A2 | Rent | 5/4/2018 |
| 6 | A | Tenant A2 | Payment | 4/30/2020 |
| 7 | B | Tenant B1 | Rent | 9/4/2019 |
| 8 | B | Tenant B1 | Payment | 12/12/2018 |
| 9 | B | Tenant B1 | Rent | 2/5/2020 |
| 10 | B | Tenant B2 | Rent | 2/12/2020 |
| 11 | B | Tenant B2 | Payment | 3/27/2018 |
| 12 | B | Tenant B2 | Rent | 4/14/2020 |
| 13 | C | Tenant C1 | Rent | 3/8/2018 |
| 14 | C | Tenant C1 | Rent | 10/16/2018 |
| 15 | C | Tenant C1 | Payment | 5/8/2019 |
| 16 | D | Tenant D1 | Rent | 10/30/2018 |
| 17 | D | Tenant D1 | Payment | 4/30/2020 |
| 18 | D | Tenant D2 | Rent | 7/30/2018 |
| 19 | D | Tenant D2 | Rent | 1/11/2019 |
| 20 | D | Tenant D2 | Payment | 3/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
- FowmySuper User
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 ) )
- AnonymousNot applicable
Thanks a lot! It's working!