Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Combining Actual and Projected Data for Average Calc

Hello - I'm working with economic variable projection data set including multiple projection version and actual results.  I'm trying to create a measure to handle the following for each factor and projection version.

  • show only actuals when version = Actual
  • when version <> Actual
    • return actual values in periods before the first projected period
    • return zero for periods after the last projection period even if actuals are available
    • return projected values in periods where both actuals and projections versions are available

I've tried switching version context using the following, it seems to work at the date level but not for the quarterly / annual aggregations. 

 

 

% Avg - Projection = 
VAR version1 = [Selected Version]
VAR table1 = FILTER ( ALL( GEA_Total[PROJECTION_VERSION] ) , GEA_Total[PROJECTION_VERSION] = version1 || GEA_Total[PROJECTION_VERSION] = "ACTUAL" )


RETURN
    SWITCH ( TRUE (), 
        ISBLANK ( CALCULATE ( AVERAGE ( GEA_Total[AMOUNT] ) , FILTER ( table1 , GEA_Total[PROJECTION_VERSION] = version1 ) ) ), 
            CALCULATE ( [% Avg - All] , FILTER ( table1 , GEA_Total[PROJECTION_VERSION] = "ACTUAL" ) ),
    CALCULATE ( [% Avg - All] , FILTER ( table1 , GEA_Total[PROJECTION_VERSION] = version1 ) )
    )

 

Actual vs Desired Outcome

 MEASURE OUTCOMEDESIRED MEASURE OUTCOMEDESIRED MEASURE OUTCOME
Year / Qtr / DateFOR PROJECTION AFOR PROJECTION A FOR PROJECTION B
    
20192.33%1.17%2.08%
11.00%1.00%1.00%
1/30/20191.00%1.00%1.00%
2/28/20191.00%1.00%1.00%
3/30/20191.00%1.00%1.00%
21.00%1.00%1.00%
4/30/20191.00%1.00%1.00%
5/30/20191.00%1.00%1.00%
6/30/20191.00%1.00%1.00%
32.00%1.67%2.33%
7/30/20191.00%1.00%1.00%
8/30/20192.00%2.00%1.00%
9/30/20192.00%2.00%5.00%
43.00%3.00%6.00%
10/30/20193.00%3.00%6.00%
11/30/20190.00%0.00%6.00%
12/30/20190.00%0.00%0.00%

 

Matrix View of Data

Average of AMOUNTColumn Labels  
Row LabelsACTUALPROJECTION APROJECTION B
20191.00%2.33%5.67%
11.00%  
1/30/20191.00%  
2/28/20191.00%  
3/30/20191.00%  
21.00%  
4/30/20191.00%  
5/30/20191.00%  
6/30/20191.00%  
31.00%2.00%5.00%
7/30/20191.00%  
8/30/20191.00%2.00% 
9/30/20191.00%2.00%5.00%
41.00%3.00%6.00%
10/30/20191.00%3.00%6.00%
11/30/20191.00% 6.00%
12/30/20191.00%  
Grand Total1.00%2.33%5.67%

 

Data Set

YEARQUARTERDATEFACTORPROJECTION_VERSIONAMOUNT
201911/30/201910YR TSYACTUAL1.00%
201912/28/201910YR TSYACTUAL1.00%
201913/30/201910YR TSYACTUAL1.00%
201924/30/201910YR TSYACTUAL1.00%
201925/30/201910YR TSYACTUAL1.00%
201926/30/201910YR TSYACTUAL1.00%
201937/30/201910YR TSYACTUAL1.00%
201938/30/201910YR TSYACTUAL1.00%
201939/30/201910YR TSYACTUAL1.00%
2019410/30/201910YR TSYACTUAL1.00%
2019411/30/201910YR TSYACTUAL1.00%
2019412/30/201910YR TSYACTUAL1.00%
201938/30/201910YR TSYPROJECTION A2.00%
201939/30/201910YR TSYPROJECTION A2.00%
2019410/30/201910YR TSYPROJECTION A3.00%
201939/30/201910YR TSYPROJECTION B5.00%
2019410/30/201910YR TSYPROJECTION B6.00%
2019411/30/201910YR TSYPROJECTION B6.00%
1 ACCEPTED SOLUTION
technolog
Super User
Super User

The main idea is to show actuals when the version is "Actual". For other versions, you want to show actual values before the first projected period, zero for periods after the last projection period, and projected values when both actuals and projections are available.

Your initial approach was to switch the version context, but it seems to work only at the date level and not for the quarterly/annual aggregations.

From the forum posts you shared, it looks like someone suggested handling this at the model level, which is a good idea. By preprocessing the data and adding attributes to handle each scenario, you can simplify the DAX calculations. This approach is often faster and more efficient than complex DAX calculations.

However, if you want to stick with DAX, the solution provided by your colleague seems to be on the right track. They're using a combination of variables and filters to create a table that combines both the selected version and actuals. They then filter out data points where actuals overlap with projections. The main idea here is to identify the first projected date for the selected projection version and then filter out any actuals that overlap with this projection. The final calculation is a simple average of the amounts in this filtered table.

In essence, the solution is creating a temporary table that combines the actuals and projections based on the rules you provided, and then it calculates the average of this combined table. This approach should give you the desired outcome for both date-level and aggregated views.

View solution in original post

3 REPLIES 3
technolog
Super User
Super User

The main idea is to show actuals when the version is "Actual". For other versions, you want to show actual values before the first projected period, zero for periods after the last projection period, and projected values when both actuals and projections are available.

Your initial approach was to switch the version context, but it seems to work only at the date level and not for the quarterly/annual aggregations.

From the forum posts you shared, it looks like someone suggested handling this at the model level, which is a good idea. By preprocessing the data and adding attributes to handle each scenario, you can simplify the DAX calculations. This approach is often faster and more efficient than complex DAX calculations.

However, if you want to stick with DAX, the solution provided by your colleague seems to be on the right track. They're using a combination of variables and filters to create a table that combines both the selected version and actuals. They then filter out data points where actuals overlap with projections. The main idea here is to identify the first projected date for the selected projection version and then filter out any actuals that overlap with this projection. The final calculation is a simple average of the amounts in this filtered table.

In essence, the solution is creating a temporary table that combines the actuals and projections based on the rules you provided, and then it calculates the average of this combined table. This approach should give you the desired outcome for both date-level and aggregated views.

Anonymous
Not applicable

Sorted this out with help from a colleague, resolved via creating a table of actuals and selected projection version and removing any periods where actuals overlapped with projection.

 

% Avg - Projection TEST2 = 
VAR version1 = [Selected Version]

VAR mindate2 = 
// identify first projected date for the selected projection version
LOOKUPVALUE(MINDATE[MINDATE],MINDATE[PROJECTION_VERSION], version1)

VAR table1 = 
// create table of both the selected version and actuals, filter out the data points where actual/projections overlap
FILTER ( 
    ADDCOLUMNS ( 
        CALCULATETABLE( GEA_Total , 
                FILTER( ALL( GEA_Total[PROJECTION_VERSION] ) , GEA_Total[PROJECTION_VERSION] = version1 || GEA_Total[PROJECTION_VERSION] = "ACTUAL" ) ) , "Y/N" , 
                    IF( mindate2 = BLANK(), FALSE(), GEA_Total[PROJECTION_VERSION] = "ACTUAL" && GEA_Total[DATE] >= mindate2 ) ), 
    [Y/N] = FALSE()  )

var calcavg = AVERAGEX( table1, [AMOUNT] )

RETURN
calcavg
Anonymous
Not applicable

Don't do this on the DAX level as it'll be complex and slow. Do it on the model level. Create a column where you'll account for each scenario on the whole date interval day by day and add an attribute(s) that will let you select a scenario you need in the code or even as a slicer maybe(?).

Then DAX will be simple like hell and fast like hell. You'll just have to write SUM( Table[Column] ) and that's it.

This is how you do it the right way. Forget about complex DAX. Don't go this path as it'll lead you astray.

Best
D

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.