Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
schoden
Post Partisan
Post Partisan

Problema de función SWITCH

Hola Comunidad,

Quiero agrupar clientes en función de años de transacción utilizando la función SWITCH.

Por ejemplo cliente Una primera transacción en 2010, la última transacción en 2020, por lo que los años de transacción son 10.

Como sabio para otros clientes.

Diferencia de fecha (medida)

MAX('Table'[Year ])-MIN('Table'[Year ])

Lealtad(Nueva Columna)

Loyalty = SWITCH(TRUE(), 
[DateDiff]>=0 && [DateDiff]<=2, "BRONZE", 
[DateDiff]>=3 && [DateDiff]<=5, "SILVER",
[DateDiff]>=6 && [DateDiff]<=8, "GOLD")

Pero la columna Lealtad cuando se coloca en una segmentación de datos, no muestra todos los grupos.

Compruebe los datos de la muestra.

https://netlinkgroup-my.sharepoint.com/:u:/g/personal/schoden_netlinkgroup_com_au/EXs9DuXKukVPvzVPZD...

Gracias de antemano.

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

Debe darle un contexto de fila para evaluar el DateDiff antes de poder hacer el cambio, intente hacer el datediff como una columna en la tabla:

Años como Cliente ?
var customer á 'Table'[Cliente]
var firstyear á MINX(FILTER(ALL('Table'),'Table'[Cliente ] - cliente), 'Tabla'[Año ])
var last year ? MAXX(FILTER(ALL('Table'),'Table'[Cliente ] - cliente), 'Tabla'[Año ])
DEVOLUCIONES el año pasado-primer año

Lealtad: SWITCH(TRUE(),
[Años como Cliente]>-0 && [Años como Cliente]<-2, "BRONCE",
[Años como Cliente]>-3 && [Años como Cliente]<-5, "PLATA",
[Años como Cliente]> 6 && [Años como Cliente]<-8, "ORO")

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
schoden
Post Partisan
Post Partisan

@AllisonKennedy Muchas gracias por la solución.

AllisonKennedy
Super User
Super User

Debe darle un contexto de fila para evaluar el DateDiff antes de poder hacer el cambio, intente hacer el datediff como una columna en la tabla:

Años como Cliente ?
var customer á 'Table'[Cliente]
var firstyear á MINX(FILTER(ALL('Table'),'Table'[Cliente ] - cliente), 'Tabla'[Año ])
var last year ? MAXX(FILTER(ALL('Table'),'Table'[Cliente ] - cliente), 'Tabla'[Año ])
DEVOLUCIONES el año pasado-primer año

Lealtad: SWITCH(TRUE(),
[Años como Cliente]>-0 && [Años como Cliente]<-2, "BRONCE",
[Años como Cliente]>-3 && [Años como Cliente]<-5, "PLATA",
[Años como Cliente]> 6 && [Años como Cliente]<-8, "ORO")

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors