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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX: How to duplicate a row based on a number in one of the columns and give it a semi-related value

I have a table (simplified) like this:

Booking #Ticket TypeTicket Count
12111Adult1
12111Child2
12111Package0

 

And a table of tickets like this:

Booking IDTicketIDTicket Type
1211112345Adult
1211112346Child
1211112347Child

 

I need to be able to output something like this:

Booking IDTicket IDTicket Type
1211112345Adult
1211112346Child
1211112347Child
12111 Package
1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

try this measure

Append = 
VAR tab =
    UNION (
        tickets,
        SELECTCOLUMNS (
            'Table',
            "Booking ID", 'Table'[Booking #],
            "Ticket ID", BLANK (),
            "Ticket Type", 'Table'[Ticket Type]
        )
    )
RETURN
    FILTER (
        tab,
        [TicketID] <> BLANK ()
            || (
                [TicketID] = BLANK ()
                    && NOT ( [Ticket Type] IN VALUES ( tickets[Ticket Type] ) )
            )
    )

result:

vxiaotang_0-1626918509372.png

 

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

try this measure

Append = 
VAR tab =
    UNION (
        tickets,
        SELECTCOLUMNS (
            'Table',
            "Booking ID", 'Table'[Booking #],
            "Ticket ID", BLANK (),
            "Ticket Type", 'Table'[Ticket Type]
        )
    )
RETURN
    FILTER (
        tab,
        [TicketID] <> BLANK ()
            || (
                [TicketID] = BLANK ()
                    && NOT ( [Ticket Type] IN VALUES ( tickets[Ticket Type] ) )
            )
    )

result:

vxiaotang_0-1626918509372.png

 

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Create a combine key

Key = [Booking ID] & [Ticket Type]

In both table and  join them on the key .

 

There two options. In visual you can use the option to show items with no data.

Or you can merge them in power query using left join. In case the above column you also need to create in power query

https://radacad.com/append-vs-merge-in-power-bi-and-power-query

Anonymous
Not applicable

I need a DAX solution unfortunately as I'm using directquery.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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