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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Ben-Jy
Frequent Visitor

Calculate amount of open order for previous months

Decidedly, I have a lot of trouble with dates.
I have a table that lists the paid orders, with an amount, a start date and a payment date.
I would like to make a measurement that calculates the total amount of open orders per month.
So per month, I want to calculate the sum of the amounts of orders that are still open, therefore not yet paid.
For the month of August, for example, I would like to calculate the total amount of orders that were created before/during August and that were paid after August.
That way, for any month, we could know how many open orders we had.

 

A picture is worth a thousand words; if I have this table :

 

Order date :  Payment date :  Amount :  
01.01.202020.08.2020100
03.01.202002.04.202056
26.01.202002.02.202025
06.02.202006.06.202031
27.02.202004.05.202065
03.03.202013.05.202078
16.03.202013.07.2020111
12.04.202015.04.2020210
23.04.202001.05.2020130
18.05.202016.06.202054
03.06.202021.08.202089
23.06.202001.08.202067
15.07.202017.07.202045
16.08.202006.09.202031

 

So, if we want to show the total amount of orders that were open during the month of March, we would have all the order which I've highlighted in bold.

If we want to show the total amount of orders that were open during the month of May, we would have all the order which I've underlined.

I need this information to have like a history of the previous months, not only the information for the actual date (TODAY())

 

Hope it's clear.


Thank you 🙂

 

7 REPLIES 7
jdbuchanan71
Super User
Super User

@TwinJohnson 

That would be something along these lines.

Open Orders = 
VAR _first = FIRSTDATE ( Dates[Date] )
VAR _last = LASTDATE ( Dates[Date] )
RETURN
CALCULATE(
    [Order Amount],
    Orders[Order Date] <= _last,
    ( Orders[Payment Date] >= _first || ISBLANK ( Orders[Payment Date] ) ),
    CROSSFILTER(Dates[Date],Orders[Order Date],None)
)

thank you so much @jdbuchanan71 , worked perfectly.

v-lili6-msft
Community Support
Community Support

hi  @Ben-Jy 

Here is a similar post for you refer to;

https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365

 

for your case, just add a Calendar table, then create a measure as below:

Total Amount = 
VAR tmpCalendar = ADDCOLUMNS('Calendar',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0#")))
VAR tmpBilling = ADDCOLUMNS('Table',"MonthYearBegin",VALUE(YEAR([Order date :]) & FORMAT(MONTH([Order date :]),"0#")),
                                      "MonthYearEnd",VALUE(YEAR([Payment date :]) & FORMAT(MONTH([Payment date :]),"0#")))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBilling,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "Year",[Year],
    "Month",[Month],
    "Amount",[Amount :]
)
RETURN SUMX(tmpTable,[Amount])

Result:

2.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@Ben-Jy , refer if this blog.  A formula current employee should work for you. There is prior formula also there .

 

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

@Ben-Jy 

I have added 2 measures in my sample, the first is just the sum of order amount.

Order Amount = SUM ( Orders[Amount] )

The second calcuates the order amount based on the order date and paid date.  It assumes there is a dates table and the dates table is linked to the orders table on the order date.  For the measure to work we have to deactivate the relationship.

Open Orders = 
VAR _first = FIRSTDATE ( Dates[Date] )
VAR _last = LASTDATE ( Dates[Date] )
RETURN
CALCULATE(
    [Order Amount],
    Orders[Order Date] <= _last,
    Orders[Payment Date] >= _first,
    CROSSFILTER(Dates[Date],Orders[Order Date],None)
)

jdbuchanan71_0-1598017652812.png

I have attached my sample file for you to look at.

 

@jdbuchanan71 @ I have a similar problem but if the payment date is blank then this should be counted as an open order too, what would the formula be if to sum the total between the last and first and blanks

Thank you,

 

 Orders[Order Date] <= _last,
    Orders[Payment Date] >= _first,

 

Anonymous
Not applicable

nvm

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.