Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi all
I am trying to implement some Dax to replicate an excel formula. The formula uses 2 measures (Actual, Budget) to determine the value for a third (Forecast). A date dimension is used to determine the sequence of values and calculate the budget remaining until the end of the year and the actual year to date.
-------------------
Row 1 to 4 show the required output, row 6 is the actual output using the dax I have so far
This link is the actual spreadsheet Forecast Measure
--------------------------------------
Sudocode for the required output
If first month in the sequence
If Actual is blank
Sum of Budget
else
Actual until this period plus sum of Budget for rest of the year
else
If Actual is blank
Use last non blank Forecast
else
Actual until this period plus sum of Budget for rest of the year
end
------------------
This is the dax I have so far
Forecast:=
IF(
/* No actual then use the value from the last calculated value */
ISBLANK([Actual]),
CALCULATE(
[Budget Rest Of Year] + [Actual YTD],
LASTNONBLANK (
'Accounting Period'[Month],
[Budget Rest Of Year] + [Actual YTD]
)
),
/* Otherwise calculate for the current period */
[Budget Rest Of Year] + [Actual YTD]
)
Any help very much appreciated
Monty
hi, @Monty0
You may try to this way as below:
Step1:
Add an index column for date(month ) column.
Index = RANKX(Table1,Table1[Date],,ASC ,Dense)
Step2:
Use this formula to create the result measure
Result = var _firstmonth=CALCULATE(FIRSTDATE(Table1[Date]),ALLSELECTED(Table1)) var no1=IF( ISBLANK(CALCULATE(SUM(Table1[Actual]),FILTER(Table1,Table1[Date]=_firstmonth))),SUM(Table1[Budget]),CALCULATE(SUM(Table1[Actual]),FILTER(ALLSELECTED(Table1),Table1[Index]<=MAX(Table1[Index])))+CALCULATE(SUM(Table1[Budget]),FILTER(ALLSELECTED(Table1),Table1[Index]>MAX(Table1[Index])))) var no2=IF( ISBLANK(CALCULATE(SUM(Table1[Actual]))),LASTNONBLANK(Table1[Forecast],SUM(Table1[Forecast])),CALCULATE(SUM(Table1[Actual]),FILTER(ALLSELECTED(Table1),Table1[Index]<=MAX(Table1[Index])))+CALCULATE(SUM(Table1[Budget]),FILTER(ALLSELECTED(Table1),Table1[Index]>MAX(Table1[Index])))) return IF(SELECTEDVALUE(Table1[Date])=_firstmonth,no1,no2)
Result:
here is pbix file, please try it.
Best Regards,
Lin
Monty,
Before I dive into an explanation, does this look about right?
It is assuming it restarts on the 1st of year
Hi Nick
Thanks for the response. Yes the value will reset after a fiscal year but yes, your example looks correct assuming that was 01/01.
Monty
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
94 | |
75 | |
63 | |
62 |
User | Count |
---|---|
137 | |
105 | |
104 | |
80 | |
63 |