Forum Discussion

anandav's avatar
anandav
Skilled Sharer
8 years ago
Solved

How to reference columns in virtual tables?

Hi,   I am creating a virtual table usingVAR. How can I refer to the columns of this newly created virtual table in the same table creation DAX? New Table = VAR JointTable = NATURALLEFTOUTERJOIN(...
  • OwenAuger's avatar
    OwenAuger
    8 years ago

    Hi again anandav

     

    Thanks for the additional info.

    From what you've provided, could I suggest a different approach, as doing the fill-down in DAX is possible but a little awkward.

     

    I'm making an assumption that you are really interested in SeatNum and Booked Customer from your screenshot below. If so, I would propose this:

     

     

    DAX Table = 
    VAR SeatNumbersPlusBookings = 
        GENERATEALL (
            SeatNumbers,
            GENERATE (
                SeatBookings,
                INTERSECT (
                    GENERATESERIES ( SeatBookings[Seat Start], SeatBookings[Seat End] ),
                    { SeatNumbers[SeatNum] }
                )
            )
        )
    VAR FinalTable =
        SELECTCOLUMNS (
            SeatNumbersPlusBookings,
            "SeatNum", SeatNumbers[SeatNum],
            "Booked Customer",
            VAR CurrentCustomer = SeatBookings[Customer]
            RETURN
                IF ( ISBLANK ( CurrentCustomer ), "Empty", CurrentCustomer )
        )
    RETURN
        FinalTable

    I'm using GENERATEALL to do the join rather than NATURALLEFTOUTERJOIN since your physical SeatBookings table don't have all the required values (since it contains Seat Start and Seat End), and GENERATE to convert the start/end values to a range.

     

     

    You could of course include additional columns on top of the two output by the above.

     

    Regards,

    Owen