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
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
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.