Forum Discussion
DataUsurper
6 years agoHelper 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 ...
v-frfei-msft
6 years agoCommunity 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]
Pbix as attached.
DataUsurper
6 years agoHelper II
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).