Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hola a todos
Estoy tratando de escribir la lógica en PowerBI para devolver un resultado basado en las últimas transacciones x(5) de todos los proveedores. este resultado debería decirme si los proveedores me han estado contabilizando el mismo precio o no. Sé cómo usar un filtro de fecha para el mes actual o x días anteriores. Pero en este caso, no sé cómo filtrar mi medida para comprobar las últimas 5 transacciones. Esto tiene que hacerse para todos los proveedores (en mi conjunto de datos tengo cientos).
Este es mi conjunto de datos de ejemplo. Debajo mostraré mi resultado esperado:
| SupplierName | InvoiceID | SamePrice True/False | PaymentDate |
| Amazon | A-10 | Verdad | 31-12-2020 |
| Amazon | AA-10 | Verdad | 1-1-2021 |
| Amazon | A-23 | Verdad | 2-1-2021 |
| Amazon | A-11 | Verdad | 4-1-2021 |
| Amazon | A-13 | Verdad | 5-1-2021 |
| Amazon | AA-290 | Verdad | 7-1-2021 |
| Amazon | A-5 | Verdad | 7-1-2021 |
| Ebay | E-1 | Verdad | 4-1-2021 |
| Ebay | E-2 | Falso | 5-1-2021 |
| Ebay | EE-1 | Verdad | 6-1-2021 |
| Ebay | E-31 | Verdad | 8-1-2021 |
| Ebay | E-9 | Verdad | 12-1-2021 |
| Ebay | E-111 | Verdad | 13-1-2021 |
| Wallmart | W-4 | Verdad | 5-1-2021 |
| Wallmart | W-5 | Verdad | 5-1-2021 |
| Wallmart | W-6 | Verdad | 6-1-2021 |
| Wallmart | W-9 | Verdad | 9-1-2021 |
Resultado esperado
| Proveedores | Total de Transacciones | SamePriceLast(5)Transacciones |
| Amazon | 7 | Verdad |
| Ebay | 6 | Falso |
| Wallmart | 4 | False (porque es necesario realizar 5 transacciones) |
Gracias amablemente por su tiempo.
Solved! Go to Solution.
No @DeBIe,
Puede utilizar el siguiente método para satisfacer sus necesidades:
Paso 1: Agregue una columna de índice:
Paso 2: Cree tres medidas como:
Total Transactions =
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[SupplierName]='Table'[SupplierName]
))measure 1 =
var _rank=RANKX(
FILTER(
ALL('Table'),
'Table'[SamePrice True/False]=TRUE()&& 'Table'[SupplierName]=MAX('Table'[SupplierName])
),
CALCULATE(MAX('Table'[PaymentDate])),,DESC
)
Return
IF(SELECTEDVALUE('Table'[SamePrice True/False])=FALSE(),BLANK(),IF(_rank<=5,1,0)
)SamePriceLast(5)Transactions =
var _index=CALCULATE(MIN('Table'[Index]),FILTER(ALLSELECTED('Table'),'Table'[measure 1]&&'Table'[SupplierName]=MAX('Table'[SupplierName])))
var _indexmax=CALCULATE(MAX('Table'[Index]),FILTER(ALLSELECTED('Table'),'Table'[measure 1]&&'Table'[SupplierName]=MAX('Table'[SupplierName])))
Return
IF(_indexmax-_index<>4,FALSE(),TRUE())Paso 3: Aquí está la salida:
Aquí está la demostración, por favor pruébelo: Cómo usar el filtro basado en las últimas transacciones x
Saludos
Enlace
No @DeBIe,
Puede utilizar el siguiente método para satisfacer sus necesidades:
Paso 1: Agregue una columna de índice:
Paso 2: Cree tres medidas como:
Total Transactions =
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[SupplierName]='Table'[SupplierName]
))measure 1 =
var _rank=RANKX(
FILTER(
ALL('Table'),
'Table'[SamePrice True/False]=TRUE()&& 'Table'[SupplierName]=MAX('Table'[SupplierName])
),
CALCULATE(MAX('Table'[PaymentDate])),,DESC
)
Return
IF(SELECTEDVALUE('Table'[SamePrice True/False])=FALSE(),BLANK(),IF(_rank<=5,1,0)
)SamePriceLast(5)Transactions =
var _index=CALCULATE(MIN('Table'[Index]),FILTER(ALLSELECTED('Table'),'Table'[measure 1]&&'Table'[SupplierName]=MAX('Table'[SupplierName])))
var _indexmax=CALCULATE(MAX('Table'[Index]),FILTER(ALLSELECTED('Table'),'Table'[measure 1]&&'Table'[SupplierName]=MAX('Table'[SupplierName])))
Return
IF(_indexmax-_index<>4,FALSE(),TRUE())Paso 3: Aquí está la salida:
Aquí está la demostración, por favor pruébelo: Cómo usar el filtro basado en las últimas transacciones x
Saludos
Enlace
Algo como lo siguiente debería funcionar
SamePriceLast(5)Transactions = IF (HASONEFILTER(Transactions[SupplierName]),
var maxDate = MAX(Transactions[PaymentDate].[Date])
var last5dates = TOPN(5, CALCULATETABLE(Transactions, Transactions[PaymentDate].[Date] <= maxDate), Transactions[PaymentDate])
return countrows( FILTER( last5dates, [SamePrice True/False] = TRUE())) = 5
,"N/A")
Primero compruebo si somos filtrados por el proveedor (es decir, si el proveedor está en las filas o si se selecciona un solo proveedor en un filtro)
Luego tomaré la fecha máxima (en caso de que se filtre la fecha, así que si filtra para enero de 2021 esta medida solo considerará las transacciones en o antes del 31 de enero de 2021) y luego obtendrá las 5 transacciones principales antes de la fecha máxima. A partir de ahí cuento las filas donde el mismo precio es verdadero y comprobar si eso es igual a 5.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.