Forum Discussion

mrothschild's avatar
mrothschild
Icon for Continued Contributor rankContinued Contributor
3 years ago
Solved

GENERATESERIES with SELECTEDVALUE

PBIX sample file is here: https://drive.google.com/file/d/13w7kMB_WKJABXnezPOrQhqlOFUXP4Wcl/view?usp=sharing   I'm trying to allow a user to effectively create a calculated table of a start point a...
  • mrothschild's avatar
    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_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