Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hola
Estoy tratando de crear una medida que calcula el "Volumen de compra" (Precio actual * Demanda) por artículo y proveedor para un mes determinado.
He configurado tres tablas (Precio de compra, Supplers y DemandR12), ver ejemplo a continuación:
La tabla PurchasePrice incluye entradas cada vez que cambia un precio de un artículo:
ItemNo | Fecha | Precio |
A | 2020-11-01 | 1 |
B | 2020-10-01 | 2 |
C | 2020-09-01 | 3 |
A | 2020-09-01 | 2 |
B | 2020-06-01 | 4 |
C | 2020-05-01 | 6 |
Tabla de proveedores
Proveedor | ItemNo |
Proveedor X | A |
Proveedor X | B |
Proveedor Y | C |
Tabla DemandR12
ItemNo | DemandR12 |
A | 100 |
B | 150 |
C | 200 |
Para calcular el volumen de compra por artículo para noviembre y septiembre estoy seleccionando el último precio de compra (del mes seleccionado o más) * DemandR12:
Total sales volume November 2020
Item A => 1 * 100 = 100 (Supplier X)
Item B => 2 * 150 = 300 (Supplier X)
Item C => 3 * 200 = 600 (Supplier Y)
Total = 1000
Total sales volume September 2020
Item A => 2 * 100 = 200 (Supplier X)
Item B => 4 * 150 = 600 (Supplier X)
Item C => 6 * 200 = 1200 (Supplier Y)
Total = 2000
También quiero poder calcular el volumen total de compra por proveedor:
Total sales volume per Supplier November 2020
Supplier X => 1*100 + 2* 150 = 400
Supplier Y => 3 * 200 = 600
Total sales volume per Supplier September 2020
Supplier X => 2*100 + 4* 150 = 800
Supplier Y => 6 * 200 = 1200
He podido crear una medida (ver más abajo) que calcula el volumen de compra por artículo, pero si quiero mostrarlo por proveedor no funciona según lo previsto. Supongo que mi variable _MaxDate seleccionará la fecha máxima para el proveedor seleccionado.
Es decir: Si el precio del artículo A cambió 2020-11-01 y el precio del artículo B 2020-10-01, entonces el _MaxDate será 2020-11-01 para el Proveedor X en noviembre de 2020. Por lo tanto, la suma del precio de la partida B es 0, por lo tanto, la fecha del artículo B es 2020-10-01.
Purchase Volume v2 =
Var _MaxDate =
// Max date for selected row
MAX(Dates[Date])
VAR _LatestPriceChangeDate =
CALCULATE(
MAX('Price Development Overtime'[Date]),
ALLSELECTED(Dates),
Dates[Date] <= _MaxDate
)
var _CurrentPrice = CALCULATE(
Sumx('Price Development Overtime', 'Price Development Overtime'[Price] * [Qty used]),
ALL(Dates[Date]),
Dates[Date] = _LatestPriceChangeDate
)
var _Result =
_CurrentPrice
Return
_Result
Podría cambiar mi procedimiento SQL para crear una entrada por mes, incluso si el precio no ha cambiado, pero eso dará lugar a una tabla muy grande.
Cualquier ayuda será muy apreciada
Br
Linus
Solved! Go to Solution.
Hola @linusb,
Puede intentar utilizar las siguientes fórmulas de medida si cumplen con sus requisitos:
Total Sales=
VAR selected =
MAX ( Date[Date] )
VAR summary =
ADDCOLUMNS (
SUMMARIZE (
DemandR12,
[ItemNo],
[DemandR12],
"Price",
VAR maxDate =
MAXX (
FILTER (
ALLSELECTED ( PurchasePrice ),
[ItemNo] = EARLIER ( [ItemNo] )
&& [Date] <= selected
),
[Date]
)
RETURN
LOOKUPVALUE (
PurchasePrice[Price],
PurchasePrice[ItemNo], [ItemNo],
PurchasePrice[Date], maxDate
)
),
"Total", [DemandR12] * [Price]
)
RETURN
SUMX ( summary, [Total] )
Total Sales Per Supplier =
VAR selected =
MAX ( Date[Date] )
VAR _list =
CALCULATETABLE ( VALUES ( Supplier[ItemNo] ), ALLSELECTED ( Supplier ) )
VAR summary =
ADDCOLUMNS (
SUMMARIZE (
FILTER ( ALLSELECTED ( DemandR12 ), [ItemNo] IN _list ),
[ItemNo],
[DemandR12],
"Price",
VAR maxDate =
MAXX (
FILTER (
ALLSELECTED ( PurchasePrice ),
[ItemNo] = EARLIER ( [ItemNo] )
&& [Date] <= selected
),
[Date]
)
RETURN
LOOKUPVALUE (
PurchasePrice[Price],
PurchasePrice[ItemNo], [ItemNo],
PurchasePrice[Date], maxDate
)
),
"Total", [DemandR12] * [Price]
)
RETURN
SUMX ( summary, [Total] )
saludos
Xiaoxin Sheng
Hola @linusb,
Puede intentar utilizar las siguientes fórmulas de medida si cumplen con sus requisitos:
Total Sales=
VAR selected =
MAX ( Date[Date] )
VAR summary =
ADDCOLUMNS (
SUMMARIZE (
DemandR12,
[ItemNo],
[DemandR12],
"Price",
VAR maxDate =
MAXX (
FILTER (
ALLSELECTED ( PurchasePrice ),
[ItemNo] = EARLIER ( [ItemNo] )
&& [Date] <= selected
),
[Date]
)
RETURN
LOOKUPVALUE (
PurchasePrice[Price],
PurchasePrice[ItemNo], [ItemNo],
PurchasePrice[Date], maxDate
)
),
"Total", [DemandR12] * [Price]
)
RETURN
SUMX ( summary, [Total] )
Total Sales Per Supplier =
VAR selected =
MAX ( Date[Date] )
VAR _list =
CALCULATETABLE ( VALUES ( Supplier[ItemNo] ), ALLSELECTED ( Supplier ) )
VAR summary =
ADDCOLUMNS (
SUMMARIZE (
FILTER ( ALLSELECTED ( DemandR12 ), [ItemNo] IN _list ),
[ItemNo],
[DemandR12],
"Price",
VAR maxDate =
MAXX (
FILTER (
ALLSELECTED ( PurchasePrice ),
[ItemNo] = EARLIER ( [ItemNo] )
&& [Date] <= selected
),
[Date]
)
RETURN
LOOKUPVALUE (
PurchasePrice[Price],
PurchasePrice[ItemNo], [ItemNo],
PurchasePrice[Date], maxDate
)
),
"Total", [DemandR12] * [Price]
)
RETURN
SUMX ( summary, [Total] )
saludos
Xiaoxin Sheng
Gracias por los comentarios. ¡La primera medida hizo el truco!
Linus