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.
Hola chicos
Estoy tratando de traducir una consulta sql anidada en power bi y mantener la capacidad de usar los campos de primer nivel como segmentaciones de datos
Aquí está el escenario
Los datos sin procesar se ven así
identificación del cliente | order_number | País | Cantidad | Fecha |
A | 1 | Vie | 100 | 01/01/2020 |
A | 1 | Vie | 100 | 01/02/2020 |
A | 1 | Vie | 100 | 01/03/2020 |
A | 2 | Uk | 100 | 01/01/2020 |
A | 2 | Uk | 100 | 01/02/2020 |
B | 3 | Nos | 100 | 01/02/2020 |
B | 3 | Nos | 100 | 01/03/2020 |
B | 4 | Vie | 100 | 01/02/2020 |
B | 4 | Vie | 100 | 01/03/2020 |
C | 5 | Nos | 100 | 01/02/2020 |
C | 5 | Nos | 100 | 01/03/2020 |
Para mi cálculo necesito hacer un primer grupo por y pasar de order_number a customer_id nivel y debe dar este
identificación del cliente | Fecha | primera suma | RowNumber | is_new_customer |
A | 01/01/2020 | 200 | 1 | 1 |
A | 01/02/2020 | 200 | 2 | 0 |
A | 01/03/2020 | 100 | 3 | 0 |
B | 01/02/2020 | 200 | 1 | 1 |
B | 01/03/2020 | 200 | 2 | 0 |
C | 01/02/2020 | 100 | 1 | 1 |
C | 01/03/2020 | 100 | 2 | 0 |
También he añadido un número de fila para ayudarme a contar el nuevo cliente (donde row_number 1 )
Y mi necesidad final debería ser así.
Fecha | contar nuevo cliente | cliente total | segunda suma |
01/01/2020 | 1 | 1 | 200 |
01/02/2020 | 2 | 3 | 500 |
01/03/2020 | 0 | 3 | 400 |
El reto aquí es crear estas medidas y ser capaz de filtrar por el país
Si selecciono "US" como país, debería tener este resultado
Fecha | contar nuevo cliente | cliente total | segunda suma |
01/01/2020 | 0 | 0 | 0 |
01/02/2020 | 2 | 2 | 200 |
01/03/2020 | 0 | 2 | 200 |
Lo intenté con una tabla de cálculo, pero es estática y no puedo usar los filtros del primer nivel
He intentado crear una medida dinámica donde he construido la última tabla de agregación para contar a los nuevos clientes, pero no se ensucia en el row_number 1, además de que es un código dax horrible, soy nuevo en power bi y ni siquiera sé si estoy en el camino correcto
aquí está el código
count new customer =
-- var v = filter(
VAR a =
ADDCOLUMNS (
SUMMARIZE (
ADDCOLUMNS (
GROUPBY (
'Fact flat';
'Fact flat'[account_id];
'Fact flat'[po_number];
'Fact flat'[the_month];
'Fact flat'[continuity];
'Fact flat'[mrr_transposed]
);
"continuity_new_customers"; IF ( 'Fact flat'[continuity] = 0; 1; 'Fact flat'[continuity] )
);
[account_id];
[the_month];
[continuity_new_customers];
"sum mrr trans"; SUM ( 'Fact flat'[mrr_transposed] )
);
"RowNumberEmbed"; RANKX (
FILTER (
GROUPBY ( 'Fact flat'; 'Fact flat'[account_id]; 'Fact flat'[the_month] );
'Fact flat'[account_id] = EARLIER ( 'Fact flat'[account_id] )
);
[the_month];
;
ASC
)
)
var b =
ADDCOLUMNS(
a;
"Previous_Value"; CALCULATE (
MAxX( SUMMARIZE (
GROUPBY (
'Fact flat';
'Fact flat'[account_id];
'Fact flat'[po_number];
'Fact flat'[the_month];
'Fact flat'[mrr_transposed]
);
[account_id];
[the_month];
"sum mrr trans"; SUM ( 'Fact flat'[mrr_transposed] )
)
; [sum mrr trans] )
; FILTER ( a; [account_id]= EARLIER([account_id]) && [the_month] < EARLIER([the_month]) && [RowNumberEmbed] = EARLIER([RowNumberEmbed] ) -1
))
)
var c =
filter(
ADDCOLUMNS(b;
"row_number_new_customer"; if([Previous_Value] <>0 ; [RowNumberEmbed];1))
; [RowNumberEmbed] = 1
)
return COUNTX(c;[account_id])
¿Puedes por favor ayudarme en este por favor, esta es la tercera semana donde estoy atrapado en esta tarea
Gracias de antemano por su ayuda
Solved! Go to Solution.
Aquí está la segunda suma. PBIX con las tres medidas se incluye como un archivo adjunto a continuación.
second sum =
VAR __Date = MAX('Table'[date])
VAR __Country = SELECTCOLUMNS('Table',"Country",[country])
VAR __Table =
SUMMARIZE(
FILTER(
ALL('Table'),
[country] IN __Country
),
[date],
"Sum",SUM('Table'[amount])
)
VAR __Sum = SUMX(FILTER(__Table,[date] = __Date),[Sum])
RETURN
IF(ISBLANK(__Sum),0,__Sum)
Aquí está la segunda suma. PBIX con las tres medidas se incluye como un archivo adjunto a continuación.
second sum =
VAR __Date = MAX('Table'[date])
VAR __Country = SELECTCOLUMNS('Table',"Country",[country])
VAR __Table =
SUMMARIZE(
FILTER(
ALL('Table'),
[country] IN __Country
),
[date],
"Sum",SUM('Table'[amount])
)
VAR __Sum = SUMX(FILTER(__Table,[date] = __Date),[Sum])
RETURN
IF(ISBLANK(__Sum),0,__Sum)
Cliente total:
total customer =
VAR __Date = MAX('Table'[date])
VAR __Country = SELECTCOLUMNS('Table',"Country",[country])
VAR __Table =
SUMMARIZE(
FILTER(
ALL('Table'),
[country] IN __Country
),
[customer id],
"Date",MIN('Table'[date])
)
VAR __Count = COUNTROWS(FILTER(__Table,[Date]<=__Date))
RETURN
IF(ISBLANK(__Count),0,__Count)
Aquí está contar nuevo cliente:
count new customer =
VAR __Date = MAX('Table'[date])
VAR __Country = SELECTCOLUMNS('Table',"Country",[country])
VAR __Table =
SUMMARIZE(
FILTER(
ALL('Table'),
[country] IN __Country
)
,[customer id],"Date",MIN('Table'[date])
)
VAR __Count = COUNTROWS(FILTER(__Table,[Date] = __Date))
RETURN
IF(ISBLANK(__Count),0,__Count)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |
User | Count |
---|---|
2 | |
2 | |
2 | |
1 | |
1 |