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 all,
So I found this great formula on the forum for calculating a measure for FYTD, and then having the lines stop and not continue on until the end of the calendar year. However, there is one issue, the calculation is being done too well, I have different categories in which I am summing TIME[Duration] to date, and some are much less used that others. See my chart below, you can see that the light purple is not continuing to the end and it is because the last entry date for that particular category was a few weeks ago. What can I change in the measure to get the line to continue to where it is caught up with the rest of the categories.
Cumulative Hours by Day =
VAR LastDate1 = CALCULATE(LASTDATE('TIME'[EntryDate]),ALL('TIME'))
RETURN
IF(
SELECTEDVALUE('Calendar Table'[Date])> LastDate1,
BLANK(),
CALCULATE(
SUM(
'TIME'[Duration]
),
FILTER(ALLSELECTED('Calendar Table'[Date]),
'Calendar Table'[Date] <= MAX('Calendar Table'[Date])
)
)
)
Solved! Go to Solution.
@Anonymous ,
I can see what you were doing, working with only variables, but unfortunately It produced the same thing that my previous formula did. However, you did set me on track for what I was looking for. I had to replace the ALL(TIME[Entry Date]) with ALLCROSSFILTERED(TIME[Entry Date]), because the ALL was still enforcing the filtering coming from the outside table. ALLCROSSFILTERED got rid of those filters coming from the table where I keep my Time Entry Categories. So my final formula wound up being:
Cumulative Cost by Day =
VAR LastDate1 = CALCULATE(LASTDATE('TIME'[EntryDate]),ALLCROSSFILTERED('TIME'))
RETURN
IF(
SELECTEDVALUE('Calendar Table'[Date])> LastDate1,
BLANK(),
CALCULATE(
SUM('TIME'[COST]),
FILTER(ALLSELECTED('Calendar Table'[Date]),
'Calendar Table'[Date] <= MAX('Calendar Table'[Date])
)
)
)
Thank you for your time and reply.
What about this?
[Cumulative Hours by Day] =
// this returns the very last
// date that exists in the
// fact table TIME regardless
// of any selections made
VAR __lastDateWithData =
CALCULATE(
MAX('TIME'[EntryDate]),
ALL('TIME')
)
var __currentDate =
SELECTEDVALUE(
'Calendar Table'[Date],
// +1 in order for this to
// work in the IF condition
__lastDateWithData + 1
)
var __result =
IF(
and(
HASONEFILTER( 'Calendar Table'[Date] )
__currentDate <= __lastDateWithData
),
CALCULATE(
SUM( 'TIME'[Duration] ),
'Calendar Table'[Date] <= __currentDate,
ALLSELECTED('Calendar Table')
)
)
return
__result
@Anonymous ,
I can see what you were doing, working with only variables, but unfortunately It produced the same thing that my previous formula did. However, you did set me on track for what I was looking for. I had to replace the ALL(TIME[Entry Date]) with ALLCROSSFILTERED(TIME[Entry Date]), because the ALL was still enforcing the filtering coming from the outside table. ALLCROSSFILTERED got rid of those filters coming from the table where I keep my Time Entry Categories. So my final formula wound up being:
Cumulative Cost by Day =
VAR LastDate1 = CALCULATE(LASTDATE('TIME'[EntryDate]),ALLCROSSFILTERED('TIME'))
RETURN
IF(
SELECTEDVALUE('Calendar Table'[Date])> LastDate1,
BLANK(),
CALCULATE(
SUM('TIME'[COST]),
FILTER(ALLSELECTED('Calendar Table'[Date]),
'Calendar Table'[Date] <= MAX('Calendar Table'[Date])
)
)
)
Thank you for your time and reply.
@Anonymous
Yes I have Bidirectional filters enabled for the Calendar table that Im trying to filter. ALLCROSSFILTERED removes all of the filters which are being applied across both tables, which results in the measure evaluating the measure for all of the rows in CalendarTable[Date], and not the rows specific to my Time Entry Category. See the documentation on ALLCROSSFILTERED for a good example.
https://docs.microsoft.com/en-us/dax/allcrossfiltered-function-dax
Caz
@Caz_16 .Have you tried datesytd?
example
YTD = CALCULATE(SUM('Time'[Duration]),DATESYTD('Date'[Date],"12/31")) // Change end date based on your FY
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 |