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
ChrisHill
Frequent Visitor

Conditionally change row values based on previous row

I need to provide ticket type counts for each person and our CRM counts upgrades as a quantity even if a ticket was issued previously. If I choose a free ticket at checkout and later upgrade that ticket, the CRM shows two tickets issued. If I choose a free ticket and select an upgrade in the same transaction it is one ticket. When I have an upgrade transaction I need to check previous transactions and if there has been a free ticket issued, don't count the free ticket, just count the upgrade. If one upgrade is purchased and two free tickets had previously been issued, the count would be one free and one upgrade. The same needs to happen with "Paid" tickets and upgrades to "Paid". The difference between free and paid is club members get a maximum of 2 free tickets and non-members cannot get free tickets. Let me provide some data and then what my end report should look like.

 

This is what our CRM provides

TransactionCustomerTicket_TypeQtyPaid
1SallyFree20
2SallyFree Upgrade125
3JohnFree Upgrade250
4RichardPaid135
5WillisPremium175
6WillisFree10
7DanielPaid270
8DanielPaid Upgrade125
9BridgetFree20
10BridgetFree Refund10
11BridgetPremium2150
12BobFree10
13BobFree10
14BobFree Upgrade125
15BobFree Upgrade125
16SallyPaid135

 

This is what I need to provide

ticket results.png

2 ACCEPTED SOLUTIONS
VIJAYKUMART
Resolver I
Resolver I

it is feasible when create separate measures for each ticket type.

hope it helps.

measures to create:

1. Total Qty = SUM(Sheet1[Qty])

2. Free = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Free")

3. Free Upgrade = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Free Upgrade")

4. Paid Qty = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Paid")
5. 
Paid Upgrade = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Paid Upgrade")

6. Premium = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Premium")

 

VIJAYKUMART_0-1647254521416.png

VIJAYKUMART_1-1647254580957.png

 

View solution in original post

v-yanjiang-msft
Community Support
Community Support

Hi @ChrisHill ,

According to your description, here's my solution.

1. First, we should create a new table, as in your calculation, the ticket type "Premium" belongs to "Paid", but some customer hasn't the type "Paid", for example "Bridget".

Create a new table, don't make relationship between the two tables.

vkalyjmsft_1-1647420457250.png

Table 2 = GENERATE(VALUES('Table'[Customer]),VALUES('Table'[Ticket_Type]))

2. Create a measure.

Measure =
VAR _Q =
    SWITCH (
        MAX ( 'Table 2'[Ticket_Type] ),
        "Free Upgrade",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] = "Free Upgrade"
                ),
                'Table'[Qty]
            ),
        "Free",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] = "Free"
                ),
                'Table'[Qty]
            )
                - SUMX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                            && 'Table'[Ticket_Type] IN { "Free Upgrade", "Free Refund" }
                    ),
                    'Table'[Qty]
                ),
        "Paid Upgrade",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] = "Paid Upgrade"
                ),
                'Table'[Qty]
            ),
        "Paid",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] IN { "Paid", "Premium" }
                ),
                'Table'[Qty]
            )
                - SUMX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                            && 'Table'[Ticket_Type] = "Paid Upgrade"
                    ),
                    'Table'[Qty]
                )
    )
RETURN
    IF ( _Q <= 0, BLANK (), _Q )

Put the columns in the new table and the measure in a matrix, get the expected result.

vkalyjmsft_2-1647420533304.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

 

View solution in original post

3 REPLIES 3
v-yanjiang-msft
Community Support
Community Support

Hi @ChrisHill ,

According to your description, here's my solution.

1. First, we should create a new table, as in your calculation, the ticket type "Premium" belongs to "Paid", but some customer hasn't the type "Paid", for example "Bridget".

Create a new table, don't make relationship between the two tables.

vkalyjmsft_1-1647420457250.png

Table 2 = GENERATE(VALUES('Table'[Customer]),VALUES('Table'[Ticket_Type]))

2. Create a measure.

Measure =
VAR _Q =
    SWITCH (
        MAX ( 'Table 2'[Ticket_Type] ),
        "Free Upgrade",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] = "Free Upgrade"
                ),
                'Table'[Qty]
            ),
        "Free",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] = "Free"
                ),
                'Table'[Qty]
            )
                - SUMX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                            && 'Table'[Ticket_Type] IN { "Free Upgrade", "Free Refund" }
                    ),
                    'Table'[Qty]
                ),
        "Paid Upgrade",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] = "Paid Upgrade"
                ),
                'Table'[Qty]
            ),
        "Paid",
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                        && 'Table'[Ticket_Type] IN { "Paid", "Premium" }
                ),
                'Table'[Qty]
            )
                - SUMX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Customer] = MAX ( 'Table 2'[Customer] )
                            && 'Table'[Ticket_Type] = "Paid Upgrade"
                    ),
                    'Table'[Qty]
                )
    )
RETURN
    IF ( _Q <= 0, BLANK (), _Q )

Put the columns in the new table and the measure in a matrix, get the expected result.

vkalyjmsft_2-1647420533304.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

 

I like this solution and it will actually help me out with another similar issue - just a little more complex. I'll be adding in guests to purchasers.

VIJAYKUMART
Resolver I
Resolver I

it is feasible when create separate measures for each ticket type.

hope it helps.

measures to create:

1. Total Qty = SUM(Sheet1[Qty])

2. Free = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Free")

3. Free Upgrade = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Free Upgrade")

4. Paid Qty = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Paid")
5. 
Paid Upgrade = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Paid Upgrade")

6. Premium = CALCULATE([Total Qty],Sheet1[Ticket_Type]="Premium")

 

VIJAYKUMART_0-1647254521416.png

VIJAYKUMART_1-1647254580957.png

 

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.