Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi Gurus,
I have two tables like in the picture. There is a relationship between 'Calendar'[Date] and 'Asset Register'[Start Date].
Now I want to do a sum for [Monthly Depreciation] from the Asset Register table, however use the [Year] and [Month] from the 'Calendar' table as the row element to display the result. The requirement is simple, sum rows in column 'Asset Register'[Monthly Depreciation] if 'Calendar'[Year] and [Month] (e.g. 1 Jan 23) is between the 'Asset Register'[Start Date] and [End Date].
I have tried so many dax but couldn't work out the correct answer (also in the picture below). I know the relationship cause part of the problem but I cannot remove it because there are other measures using it.
Please help...
Solved! Go to Solution.
Hi @clubspec
You can use the CROSSFILTER function to remove the relationship just for this measure.
Something like this:
Monthly Dep =
VAR _MaxDate = MAX('Date'[Date])
VAR _Result =
CALCULATE(
SUM('Asset Register'[Monthly depreciation]),
CROSSFILTER('Date'[Date], 'Asset Register'[Start Date], None),
'Asset Register'[Start Date] <= _MaxDate,
'Asset Register'[End Date] >= _MaxDate
)
RETURN
_Result
Hi @clubspec
please try
Total Depreciation =
VAR CurrentDate =
MIN ( 'Calendar'[Date] )
VAR T1 =
CALCULATETABLE ( 'Asset Register', ALL ( 'Calendar' ) )
VAR T2 =
FILTER (
T1,
'Asset Register'[Start Date] <= CurrentDate
&& 'Asset Register'[End Date] >= CurrentDate
)
RETURN
SUMX ( T3, 'Asset Register'[Monthly Depreciation] )
Hi @clubspec
You can use the CROSSFILTER function to remove the relationship just for this measure.
Something like this:
Monthly Dep =
VAR _MaxDate = MAX('Date'[Date])
VAR _Result =
CALCULATE(
SUM('Asset Register'[Monthly depreciation]),
CROSSFILTER('Date'[Date], 'Asset Register'[Start Date], None),
'Asset Register'[Start Date] <= _MaxDate,
'Asset Register'[End Date] >= _MaxDate
)
RETURN
_Result
Thank you so much Paul, it is working 🙂
Hi @clubspec
I understand that your data, at least from picture, for Calendar / Date Table seems find (one day / date as unique and that table as Date table featured in PowerBI).
Still to "leverage" PowerBI features for calculating / reporting MTD amounts your data should be on respective granularity, meaning one single date: day or monthly level only. It will be great if you already have or you could have that level of data per asset item. It is a bit confusing seeing your column "Monthly Depreciation" and next two dates like period. It could be that you need to use PQ transformation or somehow prepare that to be with just one monthly dates / amounts, before any DAX. I do not know it by heart :). I hope this help.
Proud to be a Super User!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 23 | |
| 14 | |
| 10 | |
| 6 | |
| 5 |