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
Syndicate_Admin
Administrator
Administrator

Valor de búsqueda con varios filtros

Hola Equipo,
Tengo dos tablas, Ventas y Moneda. Vea a continuación:

Annotation 2021-06-23 133645.jpg
Me gustaría rellenar Sales.Exchange Rate GBP y Sales.Exchange Rate USD con los tipos de cambio de la tabla de divisas (los valores anteriores son mis resultados esperados)
La lógica que necesito usar se ve algo como esto (para GBP):

select earliest exchange rate from Currency where Sales.Currency = Currency.Source and Currency.Target = 'GBP' and Sales.Date > Currency.Date


¿Cómo puedo lograr esto?

1 ACCEPTED SOLUTION

https://www.dropbox.com/s/o04lz90nbzttotv/reporting%20model.pbix?dl=0

Tipo de cambio GBP CC=
VAR sourcecurrency = Solicitudes[Moneda]
VAR targetcurrency = "GBP"
VAR currentdate = Solicitudes[Fecha solicitada]
VAR maxcurrencydate =
CALCULAR (
MAX ( 'Moneda'[fecha] ),
FILTRO (
«Moneda»,
'Moneda'[fecha] <= fecha actual
&& 'Moneda'[sourcecurrency] = sourcecurrency
&& 'Moneda'[targetcurrency] = targetcurrency
)
)
devolución
CALCULAR (
CALCULATE ( SUM ( 'Moneda'[tipo de cambio] ) ),
FILTRO (
«Moneda»,
'Moneda'[fecha] = maxcurrencydate
&& 'Moneda'[sourcecurrency] = sourcecurrency
&& 'Moneda'[targetcurrency] = targetcurrency
)
)

View solution in original post

7 REPLIES 7
Syndicate_Admin
Administrator
Administrator

Gracias @Jihwan_Kim ,

Agradezco el tiempo que pasó haciendo esto, voy a tratar de que funcione

Syndicate_Admin
Administrator
Administrator

Picture1.png

Cantidad total : =
SUM(Ventas[Cantidad])
Moneda : =
IF( ISFILTERED(Dates[Date]),
SELECTEDVALUE(Ventas[Moneda]))
Tipo de cambio GBP =
VAR _sourcecurrency =
MAX ( SourceCurrency[Origen] )
VAR _currentdate =
MAX ( Fechas[Fecha] )
devolución
SI (
NOT ISBLANK ( [Cantidad total :] )&&&ISFILTERED(Fechas[Fecha]),
CALCULAR (
LASTNONBLANKVALUE (
Fechas[Fecha],
CALCULAR (
SUM ( 'Moneda'[Tipo] ),
FILTRO (
«Moneda»,
'Moneda'[Fuente] = _sourcecurrency
&& 'Moneda'[Objetivo] = "GBP"
)
)
),
FILTRO ( TODOS ( Fechas ), Fechas[Fecha] <= _currentdate )
)
)
Tipo de cambio USD =
VAR _sourcecurrency =
MAX ( SourceCurrency[Origen] )
VAR _currentdate =
MAX ( Fechas[Fecha] )
devolución
SI (
NOT ISBLANK ( [Cantidad total :] ) && ISFILTERED(Fechas[Fecha]),
CALCULAR (
LASTNONBLANKVALUE (
Fechas[Fecha],
CALCULAR (
SUM ( 'Moneda'[Tipo] ),
FILTRO (
«Moneda»,
'Moneda'[Fuente] = _sourcecurrency
&& 'Moneda'[Objetivo] = "USD"
)
)
),
FILTRO ( TODOS ( Fechas ), Fechas[Fecha] <= _currentdate )
)
)

Veo que ha creado una tabla SourceCurrency, ¿es este un paso necesario además de mi tabla de moneda actual? Mis monedas de origen tienen más que solo AUD, así que idealmente preferiría no tener que crear esto

J

Tienes razón.
Si no tiene otras monedas, no es obligatoriamente necesario.

Hay @Jihwan_Kim

He intentado implementar su solución pero no está funcionando, he adjuntado un enlace a un modelo PowerBI. Como puede ver, estoy tratando de agregar una nueva columna a mi tabla 'Solicitudes' pero no está devolviendo resultados

https://1drv.ms/u/s!Avci50weR29DvlH-xbTb5oK5NI7U?e=qyjClq

https://www.dropbox.com/s/o04lz90nbzttotv/reporting%20model.pbix?dl=0

Tipo de cambio GBP CC=
VAR sourcecurrency = Solicitudes[Moneda]
VAR targetcurrency = "GBP"
VAR currentdate = Solicitudes[Fecha solicitada]
VAR maxcurrencydate =
CALCULAR (
MAX ( 'Moneda'[fecha] ),
FILTRO (
«Moneda»,
'Moneda'[fecha] <= fecha actual
&& 'Moneda'[sourcecurrency] = sourcecurrency
&& 'Moneda'[targetcurrency] = targetcurrency
)
)
devolución
CALCULAR (
CALCULATE ( SUM ( 'Moneda'[tipo de cambio] ) ),
FILTRO (
«Moneda»,
'Moneda'[fecha] = maxcurrencydate
&& 'Moneda'[sourcecurrency] = sourcecurrency
&& 'Moneda'[targetcurrency] = targetcurrency
)
)

Hay @Jihwan_Kim ,

Gracias, funciona.

Tuve que agregar una función DATEVALUE a mi variable currentdate ya que se quejaba de comparar fecha y cadenas.

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.

Top Kudoed Authors