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

Filtrar un resultado mediante Rango de FECHAS

Buenas tardes a todos, 

1.- Tengo una primera tabla que es lo programado a ventas, y una 2da tabla que es lo real vendido.

2.-La cantidad programada a ventas esta delimitada por una fecha de inicio y una fecha de fin, por lo que para un mismo producto en diferentes periodos existen diferentes cantidades programadas a venta:

 

tblPROGRAMA     
ID_programaid_Instalacionid_productostart_dateend_dateventa_programa
1AA.101-ene-2230-jun-225
2AA.101-jul-2231-dic-2210
3AA.201-ene-2231-dic-2212
4BB.101-ene-2231-dic-225
5CC.101-ene-2231-dic-228

 

3.- En la tabal Ventas los registros tienen una fecha, 

 

tblVENTAS    
ID_consumofk_instalacionfk_productodateventa_real
1AA.101-ene-222
2AA.102-ene-225
3AA.103-ene-224
4AA.104-ene-2210
5AA.105-ene-226
6AA.101-jul-2274
7AA.102-jul-2211
8AA.103-jul-2212
9AA.104-jul-2213
10AA.105-jul-229

 

4.- Mediante la fecha de venta quisiera obtener de la tabla Programa, el valor de venta_programa.  Para lo cual seria necesario :

(Programa.start_date >= Venta.date) AND (Programa.end_date <= Venta.date)

 

tablaVISUALIZACIÓN

ID_consumofk_instalacionfk_productodateventa_realventa_programa
1AA.101-ene-2225
2AA.102-ene-2255
3AA.103-ene-2245
4AA.104-ene-22105
5AA.105-ene-2265
6AA.101-jul-227410
7AA.102-jul-221110
8AA.103-jul-221210
9AA.104-jul-221310
10AA.105-jul-22910

 

 

5.- Intente utilizar: 

ventaProgramada = SUMX(Ventas,
                                LOOKUPVALUE(Programa[venta_programa],
                                Programa[id_Instalacion], Ventas[fk_instalacion],
                                Programa[id_producto], Ventas[fk_producto]))
 
Pero no se como colocar la condicion de filtrado de fechas.
 
De antemano muchas gracias por su apoyo.

 

1 ACCEPTED SOLUTION

Estaban invertidas las tablas, muchas gracias por el apoyo!

 

ventaProgramada =
                    SUMX(   FILTER(Programa,
                                Ventas[fk_instalacion] = Programa[id_Instalacion] &&
                                Programa[id_producto]= Ventas[fk_producto] &&
                                Ventas[date]>= Programa[start_date] &&
                                Ventas[date]<= Programa[end_date] ),
                            Programa[venta_programa])

View solution in original post

5 REPLIES 5
v-zhangti
Community Support
Community Support

Hi, @Cipriano 

 

You can try the following methods.

Column = 
CALCULATE (
    MAX ( tblPROGRAMA[venta_programa] ),
    FILTER (
        tblPROGRAMA,
        [id_producto] = EARLIER ( tblVENTAS[fk_producto] )
            && [start_date] = EARLIER ( tblVENTAS[date] )
    )
)
venta_programa = MAXX(FILTER(tblVENTAS,[date]<=EARLIER(tblVENTAS[date])),[Column])

vzhangti_0-1668479828164.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hola, la solución funciona de forma parcial, ya que al manejar mas instalaciones y productos deja de funcionar.

Tabla Programa:

PROGRAMA     
ID_programaid_Instalacionid_productostart_dateend_dateventa_programa
1AA.101-ene-2230-jun-225
2AA.101-jul-2231-dic-2210
3AA.201-ene-2231-dic-2212
4BB.101-ene-2231-dic-225
5CC.101-ene-2231-dic-228

 

Tabla Ventas:

VENTAS    
ID_consumofk_instalacionfk_productodateventa_real
1AA.101/01/20222
2AA.102/01/20225
3AA.103/01/20224
4AA.104/01/202210
5AA.105/01/20226
6AA.101/07/202274
7AA.102/07/202211
8AA.103/07/202212
9AA.104/07/202213
10AA.105/07/20229
11AA.201/01/20226
12BB.102/01/202274
13CC.103/01/202211
14AA.204/01/20226
15BB.105/01/202274
16CC.105/07/202211

 

Resultado esperado:

 

VENTAS     
ID_consumofk_instalacionfk_productodateventa_realventa_programa
1AA.101/01/202225
2AA.102/01/202255
3AA.103/01/202245
4AA.104/01/2022105
5AA.105/01/202265
6AA.101/07/20227410
7AA.102/07/20221110
8AA.103/07/20221210
9AA.104/07/20221310
10AA.105/07/2022910
11AA.201/01/2022612
12BB.102/01/2022745
13CC.103/01/2022118
14AA.204/01/2022612
15BB.105/01/2022745
16CC.105/07/2022118

 

Relacion Filtrada.jpg

 

Anexo el archivo trabajado: https://drive.google.com/file/d/1kE_0SFtNiD_zWG_IbwgPRS_MANhS1sYG/view?usp=sharing

amitchandak
Super User
Super User

@Cipriano ,A new column like

 


sumx(filter(Ventas, Ventas[fk_instalacion] = Programa[id_Instalacion] && Programa[id_producto]= Ventas[fk_producto] && Ventas[date]>= Programa[start_date] && Ventas[date]<= Programa[end_date] ), Ventas[venta_programa] )

 

 

refer 4 ways to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

Estaban invertidas las tablas, muchas gracias por el apoyo!

 

ventaProgramada =
                    SUMX(   FILTER(Programa,
                                Ventas[fk_instalacion] = Programa[id_Instalacion] &&
                                Programa[id_producto]= Ventas[fk_producto] &&
                                Ventas[date]>= Programa[start_date] &&
                                Ventas[date]<= Programa[end_date] ),
                            Programa[venta_programa])

Hello @amitchandak, when entering the code, it marks a reference error on the Program table, I attach the file:  https://drive.google.com/file/d/1sk1yClyp5dPLZabpiY3nMwxsyoShv-ss/view?usp=sharing 

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.