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
jacob2102
Helper II
Helper II

Valor de la fecha anterior más cercana

Buenas tardes,

 

Tengo un modelo de datos en el que estoy tratando de calcular, por medio de una columna calculada, los costes asociados a un producto, según el producto, la moneda en la que se realiza la factura y la fecha de la factura.

 

En el siguiente ejemplo, que adjunto en archivo "pbix" con datos de muestra, disponemos de dos orígenes de datos, los costes de productos en base a moneda y fecha (por las exportaciones de producto y las variaciones de coste) y las facturas de venta (identificando fecha, moneda y producto).

https://drive.google.com/file/d/1heOdC5omBtv_qOCljaHI6-AaMCDDFcBy/view?usp=sharing 

 

Mi objetivo es asociar el coste producto de la fecha anterior más cercana cuando la fecha de la factura no coincida con ninguna fecha de coste.

Por ejemplo:

  • Datos: Fecha_Coste=15/08/2021, Fecha_Factura=18/08/2021.
  • Resultado: Fecha_Factura=18/08/2021 Coste_Producto=15/08/2021.

 

Hasta ahora he conseguido obtener el coste cuando la fecha de la factura es igual a la fecha de coste, pero no consigo completar con los costes del día anterior más cercano.

Me gustaría conseguir una columna como se muestra en la siguiente imagen "Coste fecha anterior más cercana".

jacob2102_0-1629986201067.png

 

¿Cuál sería la opción y expresión adecuada para calcularlo?

Gracias. Un saludo,

Jacob

1 ACCEPTED SOLUTION

Hi @jacob2102,

Please change the 'calculate' function in the variable 'list' to 'calculatetable' to fix the issue:

Measure =
VAR dateStart =
    MIN ( Calendar[Date] )
VAR dateEnd =
    MAX ( Calendar[Date] )
VAR list =
    CALCULATETABLE (
        VALUES ( Table[Date] ),
        ALLSELECTED ( Table ),
        VALUES ( Table[ID] )
    )
RETURN
    IF (
        MINX ( list, [Date] ) = dateStart
            && MAX ( list, [Date] ) = dateEnd,
        "Y",
        "N"
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @jacob2102,

I'm not so sure about your descriptions, did you mean to filter the records with two conditions? (e.g. filter records that start at xxx, end at xxx)

If that is the case, you can use the current category as a condition to filter the date list, then you can extract the min and max date from that list as conditions to filter records.

Measure =
VAR dateStart =
    MIN ( Calendar[Date] )
VAR dateEnd =
    MAX ( Calendar[Date] )
VAR list =
    CALCULATE (
        VALUES ( Table[Date] ),
        ALLSELECTED ( Table ),
        VALUES ( Table[ID] )
    )
RETURN
    IF (
        MINX ( list, [Date] ) = dateStart
            && MAX ( list, [Date] ) = dateEnd,
        "Y",
        "N"
    )

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi,

 

Thanks for your answer, but not is possible to create this measure using the return expression using "MINX(list... && MAX(list...))".

 

Regards,

Jacob

Hi @jacob2102,

Please change the 'calculate' function in the variable 'list' to 'calculatetable' to fix the issue:

Measure =
VAR dateStart =
    MIN ( Calendar[Date] )
VAR dateEnd =
    MAX ( Calendar[Date] )
VAR list =
    CALCULATETABLE (
        VALUES ( Table[Date] ),
        ALLSELECTED ( Table ),
        VALUES ( Table[ID] )
    )
RETURN
    IF (
        MINX ( list, [Date] ) = dateStart
            && MAX ( list, [Date] ) = dateEnd,
        "Y",
        "N"
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
PaulDBrown
Community Champion
Community Champion

Tienes soluciónes en este hilo:

https://community.powerbi.com/t5/Desktop/Duplicar-filas-con-fechas-diferentes/m-p/2037653#M763738 

 

las has probado?

Si aún así tienes dudas, ponlas que te ayudaremos (pero en el hilo original por favor)

 

(y por favor, no dupliques preguntas que se dispersan soluciones y concocimientos )





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.