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

How to caculate a special cumulative rate ?

Hi,

 

I have sales data (from 2016 to today). I want to vizualize the rate of refund basing on the amount (in euros). 

 

rate :

- numerator = amount of refund sales (in euros but nevermind) refunded at this point or before

- denominator = total amount of sales (refund or not), for the total period

 

example : for 2017

- total 2017 : 10 000€

- 1 refund of 200€ the 15th january

- 1 refund of 300€ the 15th july

 

I will have 0/10000 until 15th junuary, then 200/10000 until 15th july and after that i will have 500/10000 (5%)

 

I wrote that for the numerator

 

rate = 
CALCULATE (
    SUM ( tableSales[amount] ), tableSales[refund]=="YES",
    FILTER (
        ALL ( tableSales ),
        tableSales[date] <= MAX ( tableSales[date] )
    )

 

 

I have two problems with that :

- it takes everything before the actual date of x axis, even if it's before the observed period (example : for 2017, it will also takes refunded sales in 2016...)

- it's only the numerator, I dont know how to take into account the total amount on the whole given period (period = years for some plots, and trimester for others).

 

Any idea to how update that formula ?

10 REPLIES 10
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

 

Best Regards

Allan

 

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

TableSales:

b1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

There is no relationship between two tables. You may create measures as below.

numerator = 
CALCULATE(
    SUM(TableSales[Amount]),
    FILTER(
        ALLSELECTED(TableSales),
        TableSales[Date]<=MAX('Calendar'[Date])&&
        YEAR(TableSales[Date])=YEAR(MAX('Calendar'[Date]))&&
        TableSales[Refound]="Yes"
    )
)

 

Percentage = 
DIVIDE(
    [numerator],
    CALCULATE(
        SUM(TableSales[Amount]),
        FILTER(
            ALLSELECTED(TableSales),
            YEAR(TableSales[Date])=YEAR(MAX('Calendar'[Date]))&&
            TableSales[Refound]="Yes"
        )
    )
)

 

Result:

b2.png

 

Best Regards

Allan

 

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

 

parry2k
Super User
Super User

@Anonymous As a best practice, add date dimension in your model and use it for and time intelligence calculations. Once the date dimension is added, mark it as a date table on table tools.

https://perytus.com/2020/05/22/create-a-basic-date-table-in-your-data-model-for-time-intelligence-calculations/

 

and add a measure using date dimension, instead of ALL use ALLSELECTED

 

rate = 
CALCULATE (
    SUM ( tableSales[amount] ), tableSales[refund]=="YES",
    FILTER (
        ALLSELECTED ( tableDate[Date] ),
        tableDate[date] <= MAX ( tableDate[date] )
    )

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi,

 

I dont get it at all... Are you sure it's 3 times "tableDate[Date]" ? It's never "tableSales[Date]" ?

 

And it's about a best practice but what about my 2 initials problems?  ^^ You agree it doesnt solve it ?

@Anonymous yes anywhere you are referring to the date in your measure, you will use new added Date dimension (assuming it is called tabelDate

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

But how about my 2 initials problems ?

@Anonymous not sure what you are referring to initial two problems?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable


I have two problems with that :

- it takes everything before the actual date of x axis, even if it's before the observed period (example : for 2017, it will also takes refunded sales in 2016...)

- it's only the numerator, I dont know how to take into account the total amount on the whole given period (period = years for some plots, and trimester for others).

Anonymous
Not applicable

@parry2k 

 

I tried to create 2 date tables :

- 1 date table (date) to x-axis

- 1 date table (date2) to the legend

 

and do that :

rate = 
CALCULATE (
    SUM ( tableSales[amount] ), tableSales[refund] =="YES",
    FILTER (
        ALLSELECTED( tableSales[dateRefund]) ,
         tableSales[dateRefund] <= MAX (  date[Date] )
    ),    FILTER (
        ALLSELECTED( tableSales[dateCommand]) ,
         YEAR(tableSales[dateCommand]) == YEAR(date2[Date]
    )
)

 

but it doenst work

Anonymous
Not applicable

Concerning your tips, it didnt works. It works if I change as follow :

 

CALCULATE (
    SUM ( tableSales[amount] ), tableSales[refund]=="YES",
    FILTER (
        ALLSELECTED ( tableSales[Date] ),
        tableSales[date] <= MAX ( tableDate[date] )
    )

 

And I put tableDate[date] as x-axis on the plot 

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.