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

Returning amount refunded from purchase in store but refund happens in either same store or another

Hi, i have calculation issue i've been trying to solve with different solutions from this forum but none have really worked out for me.

Let's say my table looks like the one below and i want to find out the amount refunded originating from purchases made in store 1 - both refunds that happened in the same store but also in a different store?

 

ReceiptStoreTrans_typeAmountQuantityDate
55451Purchase29912018-11-20
55451Purchase49912018-11-20
55451Purchase179912018-11-20
55451Purchase19912018-11-20
55622Purchase19912018-11-21
55141Purchase34912018-11-22
55141Purchase49912018-11-22
55455Refund-299-12018-11-26
55455Refund-499-12018-11-26
55622Refund-199-12018-11-26
55143Refund-499-12018-12-04
2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @Anonymous

 

Try the following, where Table1 is the name of the table you show. It will give you the amount refunded from purchases originated in each store.

 

1. Set Table1[Store] in the rows of a matrix visual

2. Set this measure in values of the visual

 

RefundsFromPurchasesInStore =
VAR _ReceiptsList =
    CALCULATETABLE (
        DISTINCT ( Table1[Receipt] );
        Table1[Trans_type] = "Purchase"
    )
RETURN
    SUMX (
        CALCULATETABLE (
            Table1;
            _ReceiptsList;
            Table1[Trans_type] = "Refund";
            ALL ( Table1 )
        );
        Table1[Amount] * Table1[Quantity]
    )

Code formatted with   www.daxformatter.com

 

 

View solution in original post

@Anonymous

 

Yeah, if you do a minor modification to the measure above, removing the ALL ( Table1 ) in the second CALCULATETABLE, you bring back the restriction to look in the same store:  

 

RefundsInLikeStore =
VAR _ReceiptsList =
    CALCULATETABLE (
        DISTINCT ( Table1[Receipt] );
        Table1[Trans_type] = "Purchase"
    )
RETURN
    SUMX (
        CALCULATETABLE (
            Table1;
            _ReceiptsList;
            Table1[Trans_type] = "Refund"
        );
        Table1[Amount] * Table1[Quantity]
    ) + 0

and once we have that we can use the two previous measures to get the amount refunded in other shops

 

RefundsInOtherStores = [RefundsFromPurchasesInStore] - [RefundsInLikeStore]

 

These are supposed to be used in the matrix visual (or similar) with Table1[Store] in the rows, just like [RefundsFromPurchasesInStore]

 

View solution in original post

4 REPLIES 4
AlB
Super User
Super User

Hi @Anonymous

 

Try the following, where Table1 is the name of the table you show. It will give you the amount refunded from purchases originated in each store.

 

1. Set Table1[Store] in the rows of a matrix visual

2. Set this measure in values of the visual

 

RefundsFromPurchasesInStore =
VAR _ReceiptsList =
    CALCULATETABLE (
        DISTINCT ( Table1[Receipt] );
        Table1[Trans_type] = "Purchase"
    )
RETURN
    SUMX (
        CALCULATETABLE (
            Table1;
            _ReceiptsList;
            Table1[Trans_type] = "Refund";
            ALL ( Table1 )
        );
        Table1[Amount] * Table1[Quantity]
    )

Code formatted with   www.daxformatter.com

 

 

Anonymous
Not applicable

@AlB Thank you for this!


Would it be possible to differentiate if the refund was made in the same store or in a different one? Like Store 1: 899 / Other Stores: 579

@Anonymous

 

Yeah, if you do a minor modification to the measure above, removing the ALL ( Table1 ) in the second CALCULATETABLE, you bring back the restriction to look in the same store:  

 

RefundsInLikeStore =
VAR _ReceiptsList =
    CALCULATETABLE (
        DISTINCT ( Table1[Receipt] );
        Table1[Trans_type] = "Purchase"
    )
RETURN
    SUMX (
        CALCULATETABLE (
            Table1;
            _ReceiptsList;
            Table1[Trans_type] = "Refund"
        );
        Table1[Amount] * Table1[Quantity]
    ) + 0

and once we have that we can use the two previous measures to get the amount refunded in other shops

 

RefundsInOtherStores = [RefundsFromPurchasesInStore] - [RefundsInLikeStore]

 

These are supposed to be used in the matrix visual (or similar) with Table1[Store] in the rows, just like [RefundsFromPurchasesInStore]

 

Anonymous
Not applicable

@AlB

Exactly what i was looking for!

Thanks a lot once again!

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.