Forum Discussion
GENERATESERIES with SELECTEDVALUE
- 3 years ago
Anonymous Thank you.
The following is as much for me as it is for others who come across this feed. PowerBI cannot create a new Calculated Table using input from Slicers. It can, however, create a Virtual Calculated Table in a Measure that can get to the results you want, but is difficult to audit. Accordingly, I recommend that you create a Calculated Table with "hardcoded" inputs to audit/program/build, while you're replicating the Measure output you seek using the virtual table for dynamic purposes.
This is my auditing Calculated Table. You'll note that the RETURN has to be a Table.
zzNewTable = VAR StrtDate = DATE ( 2023, 6, 1 ) VAR EndDate = EOMONTH(StrtDate,60+1) VAR CalMth = GENERATESERIES ( 0, DATEDIFF ( StrtDate, EndDate, MONTH ), 1 ) // NetRent = AcquisitionCost * LRF * (1-TechServicingFee) VAR NetRent = 10000 * 0.015 * (1-0.05) // Deployment = AcquisitionCost - LeaseTransactionCosts VAR Deployment = 10000 + 50 // Exit = AcquisitionCost * RV% - LeaseTransitionCosts VAR Exit = 10000 * 0.75 - 50 VAR T1_1 = ADDCOLUMNS( CalMth, "Date", IF([Value]=0,EOMONTH(StrtDate,[Value]),EOMONTH(StrtDate,[Value]-1)+1), "@AcqCost", 10000, "@LRF", 0.015, "@RV%", 0.75, "@LeaseTerm", 60, "@NetRent", IF([Value]=0,(-1)*Deployment,IF([Value]=61,Exit,NetRent)) , "@StartMonth", 6 ) VAR UnlevIRR = XIRR(T1_1,[@NetRent],[Date]) RETURN T1_1This is my Measure. You'll note that the RETURN needs to be a Measure (and not a Table)
zzVirtual Table Measure = VAR StrtDate = DATE ( [Measure - Start Year], [Measure - Start Month], 1 ) VAR EndDate = EOMONTH(StrtDate,[Measure - Lease Term]+1) VAR CalMth = GENERATESERIES (0, DATEDIFF (StrtDate, EndDate, MONTH ), 1 ) // NetRent = AcquisitionCost * LRF * (1-TechServicingFee) VAR NetRent = // 10000 * 0.015 * (1-0.05) [Measure - Acquisition Price] * [Measure - Lease Rate Factor] * (1-[Measure - Technical Servicing Fee]) // Deployment = AcquisitionCost - LeaseTransactionCosts VAR Deployment = // 10000 + 50 [Measure - Acquisition Price] + [Measure - Lease Transaction Costs] // Exit = AcquisitionCost * RV% - LeaseTransitionCosts VAR Exit = // 10000 * 0.75 - 50 [Measure - Acquisition Price] * [Measure - Residual Percentage] - [Measure - Lease Transaction Costs] VAR T1_1 = ADDCOLUMNS( CalMth, "Date", IF([Value]=0,EOMONTH(StrtDate,[Value]),EOMONTH(StrtDate,[Value]-1)+1), "@AcqCost", 10000, "@LRF", 0.015, "@RV%", 0.75, "@LeaseTerm", 60, "@NetRent", IF([Value]=0,(-1)*Deployment,IF([Value]=[Measure - Lease Term]+1,Exit,NetRent)) , "@StartMonth", 6 ) VAR UnlevIRR = XIRR(T1_1,[@NetRent],[Date]) RETURN UnlevIRR
Anonymous Thank you.
The following is as much for me as it is for others who come across this feed. PowerBI cannot create a new Calculated Table using input from Slicers. It can, however, create a Virtual Calculated Table in a Measure that can get to the results you want, but is difficult to audit. Accordingly, I recommend that you create a Calculated Table with "hardcoded" inputs to audit/program/build, while you're replicating the Measure output you seek using the virtual table for dynamic purposes.
This is my auditing Calculated Table. You'll note that the RETURN has to be a Table.
zzNewTable =
VAR StrtDate =
DATE ( 2023, 6, 1 )
VAR EndDate =
EOMONTH(StrtDate,60+1)
VAR CalMth =
GENERATESERIES (
0,
DATEDIFF (
StrtDate,
EndDate,
MONTH
),
1
)
// NetRent = AcquisitionCost * LRF * (1-TechServicingFee)
VAR NetRent =
10000 * 0.015 * (1-0.05)
// Deployment = AcquisitionCost - LeaseTransactionCosts
VAR Deployment =
10000 + 50
// Exit = AcquisitionCost * RV% - LeaseTransitionCosts
VAR Exit =
10000 * 0.75 - 50
VAR T1_1 =
ADDCOLUMNS(
CalMth,
"Date",
IF([Value]=0,EOMONTH(StrtDate,[Value]),EOMONTH(StrtDate,[Value]-1)+1),
"@AcqCost",
10000,
"@LRF",
0.015,
"@RV%",
0.75,
"@LeaseTerm",
60,
"@NetRent",
IF([Value]=0,(-1)*Deployment,IF([Value]=61,Exit,NetRent)) ,
"@StartMonth",
6
)
VAR UnlevIRR =
XIRR(T1_1,[@NetRent],[Date])
RETURN
T1_1
This is my Measure. You'll note that the RETURN needs to be a Measure (and not a Table)
zzVirtual Table Measure =
VAR StrtDate =
DATE ( [Measure - Start Year], [Measure - Start Month], 1 )
VAR EndDate =
EOMONTH(StrtDate,[Measure - Lease Term]+1)
VAR CalMth =
GENERATESERIES (0, DATEDIFF (StrtDate, EndDate, MONTH ), 1 )
// NetRent = AcquisitionCost * LRF * (1-TechServicingFee)
VAR NetRent =
// 10000 * 0.015 * (1-0.05)
[Measure - Acquisition Price] * [Measure - Lease Rate Factor] * (1-[Measure - Technical Servicing Fee])
// Deployment = AcquisitionCost - LeaseTransactionCosts
VAR Deployment =
// 10000 + 50
[Measure - Acquisition Price] + [Measure - Lease Transaction Costs]
// Exit = AcquisitionCost * RV% - LeaseTransitionCosts
VAR Exit =
// 10000 * 0.75 - 50
[Measure - Acquisition Price] * [Measure - Residual Percentage] - [Measure - Lease Transaction Costs]
VAR T1_1 =
ADDCOLUMNS(
CalMth,
"Date",
IF([Value]=0,EOMONTH(StrtDate,[Value]),EOMONTH(StrtDate,[Value]-1)+1),
"@AcqCost",
10000,
"@LRF",
0.015,
"@RV%",
0.75,
"@LeaseTerm",
60,
"@NetRent",
IF([Value]=0,(-1)*Deployment,IF([Value]=[Measure - Lease Term]+1,Exit,NetRent)) ,
"@StartMonth",
6
)
VAR UnlevIRR =
XIRR(T1_1,[@NetRent],[Date])
RETURN
UnlevIRR