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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
DataUsurper
Helper II
Helper II

Plotting Calculated Weekly Revenue and/or Return % between BillStart and BillEnd Dates.

Hello All  o/

 

I am attempting to create a measure to graph a calculated weekly revenue amount between an order's bill from and bill to dates. My data-model's context for those orders are per the orders' ship date, so I haven't linked either of the bill dates to the calendar table.

 

  • The calculated Wkly Revenue is : (total/order days)*7
  • The Weekly Rate of Return WROR is: Wkly Revenue/ReplacementCost

Is there an efficient way to produce this measure for graphing without creating a table (we tried that and it ended up producing 66 million records killing file performance. This was from the nifty work from a msft user on this forum, in this thread: https://community.powerbi.com/t5/Power-Query/Create-a-table-of-values-based-on-two-dates/m-p/819170#...

 

I attempted Phil's periodic billing measure but it timed out the file as the data table is just over 10m records consisting of orders' item level details, below is mine just attempting to create the measure on my data before trying to modify it for my calculated wkly amount.

Periodic Billing Attempt:

 

 

 

 

PeriodicBilling = 
VAR tmpCalendar = ADDCOLUMNS(key_Calendar,"Mo",key_Calendar[MonthNum],"Yr",key_Calendar[Year],"MonthYr",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0#")))
VAR tmpBilling = ADDCOLUMNS(tbl_Orders_DatesDays,"MonthYearBegin",VALUE(YEAR(tbl_Orders_DatesDays[BILLFROM_DATE]) & FORMAT(MONTH(tbl_Orders_DatesDays[BILLFROM_DATE]),"0#")),
                                      "MonthYearEnd",VALUE(YEAR(tbl_Orders_DatesDays[BILLTO_DATE]) & FORMAT(MONTH(tbl_Orders_DatesDays[BILLTO_DATE]),"0#")))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBilling,
            SUMMARIZE(tmpCalendar,[Yr],[Mo],[MonthYr])
        ),
        [Yr] >= [MonthYearBegin] &&
        [MonthYr] <= [MonthYearEnd]
    ),
    "Yr",[Yr],
    "Mo",[Mo],
    "Amount",[Total Line Total]
)
RETURN SUMX(tmpTable,[Amount])

 

 

 

 

 

Suggestions or ideas?

Thank you kindly.

 

Let me know if anyone needs additional info or some sample data.

4 REPLIES 4
v-frfei-msft
Community Support
Community Support

Hi @DataUsurper ,

 

Please try the optimized way.

Table = 
VAR a =
    CALENDARAUTO ()
VAR b =
    SELECTCOLUMNS (
        'Order',
        "id", 'Order'[MAIN_ORDER],
        "product", 'Order'[MAINCODE]
    )
VAR k =
    ADDCOLUMNS (
        FILTER ( CROSSJOIN ( a, b ), WEEKDAY ( [Date], 2 ) = 1 ),
        "filter",
        VAR ship =
            CALCULATE (
                MAX ( 'date days'[SHIP_DATE] ),
                FILTER ( 'date days', 'date days'[ORDERID] = [id] )
            ) - 7
        VAR returndate =
            CALCULATE (
                MAX ( 'date days'[RETURN_DATE] ),
                FILTER ( 'date days', 'date days'[ORDERID] = [id] )
            )
        RETURN
            IF ( [Date] >= ship && [Date] <= returndate, 1, 0 )
    )
RETURN
    FILTER ( k, [filter] = 1 )
Days in use2 = 
VAR st =
    CALCULATE (
        MAX ( 'date days'[SHIP_DATE] ),
        FILTER ( 'date days', 'date days'[ORDERID] = 'Table'[id] )
    )
VAR returndate =
    CALCULATE (
        MAX ( 'date days'[RETURN_DATE] ),
        FILTER ( 'date days', 'date days'[ORDERID] = 'Table'[id] )
    )
VAR maxdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            'Table',
            'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[product] = EARLIER ( 'Table'[product])
        )
    )
VAR mindate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER (
            'Table',
   'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[product] = EARLIER ( 'Table'[product])
        )
    )
RETURN
    IF (
        [Date] = mindate,
        DATEDIFF ( [Date], st, DAY ),
        IF ( [Date] = maxdate, DATEDIFF ( [Date], returndate, DAY ), 7 )
    )
Revenue2 = 
VAR suma =
    CALCULATE ( SUM ( 'Table'[Days in use2] ), ALLEXCEPT ( 'Table', 'Table'[product], 'Table'[id]) )
VAR val =
    CALCULATE (
        SUM ( 'Order'[  ITEMTOTAL  ] ),
        FILTER ( 'Order', 'Order'[MAINCODE] = 'Table'[product] )
    )
RETURN
    DIVIDE ( val, suma ) * 'Table'[Days in use2]

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Good Morning Frank @v-frfei-msft! and thank you again for jumping in this exercise.

 

Is it possible to create this as a measure rather than a table? I apologize for not being clear about that in the OP, creating a table produces too many records (66 million, housed in Access since I'm unable to create a database file or whatever that is called).

DataUsurper
Helper II
Helper II

Friendly morning bump

Afternoon bump

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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