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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ianwuk
Helper III
Helper III

How can I sum up total sales that include sales and refunds in my data?

Hello All.

Can anyone kindly help me with my issue?

 

I have this data:

DateSaleCommissionTypeName
1st March 20186833.19SaleJohn
1st March 201814975.32SaleJane
1st March 20186833.19SaleJohn
1st March 20186833.19RefundJohn
1st March 201814975.32RefundJane

 

How can I sum up total sales for each name that also minuses the refunds?  I know I need to use SumX (I think), but I am not sure how?

So, as an example, to calculate the sum of total sales for March 1st 2018 for John it should be:

68 (Sale) + 68 (Sale) - 68 (Refund) = 68 (Total Sales for John for 1st March 2018)

And then work it out the same way for all other employees (e.g. Jane).

I also want to do the same for commissions too, can anyone help me please?

Many thanks.

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

HI @ianwuk

 

Try this MEASURE

 

Total Sales =
CALCULATE ( SUM ( TableName[Sale] ), TableName[Type] = "Sale" )
    - CALCULATE ( SUM ( TableName[Sale] ), TableName[Type] = "Refund" )

Regards
Zubair

Please try my custom visuals

View solution in original post

9 REPLIES 9
Zubair_Muhammad
Community Champion
Community Champion

HI @ianwuk

 

Try this MEASURE

 

Total Sales =
CALCULATE ( SUM ( TableName[Sale] ), TableName[Type] = "Sale" )
    - CALCULATE ( SUM ( TableName[Sale] ), TableName[Type] = "Refund" )

Regards
Zubair

Please try my custom visuals

Hello @Zubair_Muhammad.

Thanks very much.   I will try this tomorrow and let you know.

On a related note, how can I group the data in my example to look like this (for a separate table).

        Day                               Name                     Total Sales    Total Refunds
1st March 2018                      John                             2                   1

1st March 2018                      Jane                              1                   1

It needs to be grouped by Name, but I don't know how to also count number of Sales and number of Refunds and group that as well to produce the above. 

Thanks.

@ianwuk

 

you can use a MEASURE like

 

Total Sales Count =
CALCULATE ( COUNTROWS ( TableName ), TableName[Type] = "Sale" )

Regards
Zubair

Please try my custom visuals

Thanks so much for this @Zubair_Muhammad!

I am nearly there now.

 

I do have one more task, how can I count the days between these two date columns and display it as a whole number?  I want to see how many days it takes for a refund to be generated after a product has been ordered.

 

The data looks like this:

Order Date                                       Refund Date

Thursday March 8th 2018               Thursday March 8th 2018
Wedndesday March 7th 2018         Thursday March 8th 2018

It should look like this:

Order Date                                       Refund Date                            Days to Refund

Thursday March 8th 2018               Thursday March 8th 2018            0
Wedndesday March 7th 2018         Thursday March 8th 2018            -1

I tried other solutions on this forum but the calculations are not what I expect to see.  Can you help at all?

For example, if I set up a new column to minus order date from refund date it is not what I expect to see above.

I set up a column like this:

Column = AffiliatesMarch2018[Order Date].[Day] - AffiliatesMarch2018[Refund Date].[Day]

It looks like this:

Capture.JPG

What is circled in blue looks correct, and is what I want, but what is calculated and circled in red looks wrong?

How can I also make it so that for any order that has  no refund date it is blank and only the orders with a refund date have a value in the new column?

Many thanks.

Hello @Zubair_Muhammad, I solved the above request.

 

Now I have one more problem please.

I created this new measure:

Refund % = AffiliatesMarch2018[Total Refunds Count]/AffiliatesMarch2018[Total Sales Count]*100

 

However, it results in some records in the column saying "Infinity" if no sales are made for example, but there is still a refund.

How can I remove "Infinity" and make it blank?

When I tried creating an IF measure it said that it could not be done because it involced text and numbers.

My measure looked like this:

Measure = IF (AffiliatesMarch2018[Total Refunds Count]/AffiliatesMarch2018[Total Sales Count]*100 = "Infinity", BLANK (),
    AffiliatesMarch2018[Total Refunds Count]/AffiliatesMarch2018[Total Sales Count]*100)

What can I do to fix this?

Many thanks.

HI @ianwuk

 

Use the DIVIDE function

 

Refund % =
DIVIDE (
    AffiliatesMarch2018[Total Refunds Count],
    AffiliatesMarch2018[Total Sales Count]
)

 

 


Regards
Zubair

Please try my custom visuals

@ianwuk

 

Also there is no need to multiply my 100.

 

From the Modelling Tab... you can select the formatting of MEASURE as percentage


Regards
Zubair

Please try my custom visuals

Thanks again @Zubair_Muhammad for all your help!

 

One more question please, if I may?

 

Right now, this PowerBi reads from a CSV file called 'March2018.csv' and all formulas and measures in Power Bi are based on that.

 

How can I make it so that, for next month, when I get a new CSV file called 'April2018.csv' with the same data, just for April, I can just load that new csv in to Power Bi and all the measures and formulas and such will use this new CSV file and I do not have to change everything manually in Power Bi?

Many thanks for your help.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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