The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
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 OUTCOME | DESIRED MEASURE OUTCOME | DESIRED MEASURE OUTCOME | |
Year / Qtr / Date | FOR PROJECTION A | FOR PROJECTION A | FOR PROJECTION B |
2019 | 2.33% | 1.17% | 2.08% |
1 | 1.00% | 1.00% | 1.00% |
1/30/2019 | 1.00% | 1.00% | 1.00% |
2/28/2019 | 1.00% | 1.00% | 1.00% |
3/30/2019 | 1.00% | 1.00% | 1.00% |
2 | 1.00% | 1.00% | 1.00% |
4/30/2019 | 1.00% | 1.00% | 1.00% |
5/30/2019 | 1.00% | 1.00% | 1.00% |
6/30/2019 | 1.00% | 1.00% | 1.00% |
3 | 2.00% | 1.67% | 2.33% |
7/30/2019 | 1.00% | 1.00% | 1.00% |
8/30/2019 | 2.00% | 2.00% | 1.00% |
9/30/2019 | 2.00% | 2.00% | 5.00% |
4 | 3.00% | 3.00% | 6.00% |
10/30/2019 | 3.00% | 3.00% | 6.00% |
11/30/2019 | 0.00% | 0.00% | 6.00% |
12/30/2019 | 0.00% | 0.00% | 0.00% |
Matrix View of Data
Average of AMOUNT | Column Labels | ||
Row Labels | ACTUAL | PROJECTION A | PROJECTION B |
2019 | 1.00% | 2.33% | 5.67% |
1 | 1.00% | ||
1/30/2019 | 1.00% | ||
2/28/2019 | 1.00% | ||
3/30/2019 | 1.00% | ||
2 | 1.00% | ||
4/30/2019 | 1.00% | ||
5/30/2019 | 1.00% | ||
6/30/2019 | 1.00% | ||
3 | 1.00% | 2.00% | 5.00% |
7/30/2019 | 1.00% | ||
8/30/2019 | 1.00% | 2.00% | |
9/30/2019 | 1.00% | 2.00% | 5.00% |
4 | 1.00% | 3.00% | 6.00% |
10/30/2019 | 1.00% | 3.00% | 6.00% |
11/30/2019 | 1.00% | 6.00% | |
12/30/2019 | 1.00% | ||
Grand Total | 1.00% | 2.33% | 5.67% |
Data Set
YEAR | QUARTER | DATE | FACTOR | PROJECTION_VERSION | AMOUNT |
2019 | 1 | 1/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 1 | 2/28/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 1 | 3/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 2 | 4/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 2 | 5/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 2 | 6/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 3 | 7/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 3 | 8/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 3 | 9/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 4 | 10/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 4 | 11/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 4 | 12/30/2019 | 10YR TSY | ACTUAL | 1.00% |
2019 | 3 | 8/30/2019 | 10YR TSY | PROJECTION A | 2.00% |
2019 | 3 | 9/30/2019 | 10YR TSY | PROJECTION A | 2.00% |
2019 | 4 | 10/30/2019 | 10YR TSY | PROJECTION A | 3.00% |
2019 | 3 | 9/30/2019 | 10YR TSY | PROJECTION B | 5.00% |
2019 | 4 | 10/30/2019 | 10YR TSY | PROJECTION B | 6.00% |
2019 | 4 | 11/30/2019 | 10YR TSY | PROJECTION B | 6.00% |
Solved! Go to Solution.
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.
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.
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
User | Count |
---|---|
27 | |
12 | |
8 | |
8 | |
5 |
User | Count |
---|---|
32 | |
15 | |
12 | |
12 | |
7 |