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
Anonymous
Not applicable

Convento de funciones de caso SQL en DAX

Hola a todos,

He creado la función de caso SQL que quiero convento en DAX, ¿alguien puede ayudarme.

case
    when
        {custbody_vm_term_type} like '%Upgrade%' 
    then
        case
            when
                {class.cseg_reporting_seg2} like'%Feature%' 
            then
                'Features'
            when
                {class.cseg_reporting_seg1} like '%Accessory%' 
            then
                'Accessories' 
            when
                {item} like '%ADD%' 
                OR {item} like '%AAL%' 
            then
                'Voice Add A Lines' 
            when
                (
                    {class} like '%Sales : Rate Plans : Prepaid%' 
                    or {class} like '%Sales : Features : Prepaid%' 
                )
            then
                'Prepaid Activations' 
            when
                {class} like '%Inventory : Equipment%' 
            then
                'Equipment' 
            else
                'Upgrades' 
        end
        when
            {custbody_vm_term_type} like '%Activation%' 
        then
            case
                when
                    (
                        {class} like '%Sales : Rate Plans : Prepaid%' 
                        or {class} like '%Sales : Features : Prepaid%' 
                    )
                then
                    'Prepaid Activations' 
                when
                    {class.cseg_reporting_seg2} like '%Feature%' 
                then
                    'Features'
    when
     {class.cseg_reporting_seg2} like '%BTS Acts%' 
    then
     'BTS Activations'
                when
                    {class.cseg_reporting_seg1} like '%Accessory%' 
                then
                    'Accessories' 
                when
                    {item} like '%ADD%' 
                    OR {item} like '%AAL%' 
                then
                    'Voice Add A Lines' 
                When
                    {class} like '%Inventory : Equipment%' 
                Then
                    'Equipment' 
                else
                    'Voice Activations' 
            end
            when
                {custbody_vm_term_type} like '%Equipment%' 
            then
                'Equipment' 
            when
                {custbody_vm_term_type} like '%Accessories%' 
            then
                'Accessories' 
            when
                {custbody_vm_term_type} like '%Feature%' 
            then
                'Features' 
            when
                {custbody_vm_term_type} is NULL 
            then
                Case
                    when
                        {class.cseg_reporting_seg2} like '%Feature%' 
                    then
                        'Features' 
                    when
                        {class.cseg_reporting_seg1} like '%Accessory%' 
                    then
                        'Accessories' 
                    when
                        {Class} like '%Sales : Rate Plans : Postpaid : Postpaid AAL%' 
                    then
                        'Voice Add A Lines' 
                    when
                        (
                            {class} like '%Sales : Rate Plans : Prepaid%' 
                            or {class} like '%Sales : Features : Prepaid%' 
                        )
                    then
                        'Prepaid Activations' 
                    when
                        {class} like '%Sales : Rate Plans : Postpaid : Postpaid%' 
                    then
                        'Voice Activations' 
                    else
                        'Equipment'
                end
                else
                    'Equipment' 
end

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hola , @M_OVAISJANZEB

La sintaxis SQL'caso... Cuando.. Entonces.. Cuando.. entonces ' corresponde a la sintaxis de Dax 'Switch'

La sintaxisSQL' LIKE'%SQLBI%' corresponde a la sintaxis Dax 'Containsstring' / 'SEARCH'

Puede comprobar si estos documentos ayudan.

from-sql-to-dax-string-comparison

dax/switch-function-dax

dax/containsstring-function-dax

dax/search-function-dax

Saludos
Equipo de soporte de la comunidad _ Eason
Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

TomMartens
Super User
Super User

Hey @M_OVAISJANZEB ,

si desea crear una columna calculada, utilice SWITCH(...) asegúrese de almacenar en caché las referencias de columna en variables como esta:

column name =
var __columnname1 = 'tablename'[columnname]
...
return
SWITCH(
    TRUE()
    , FIND("Upgrade" , __columnname1 , 1 , BLANK())
        , SWITCH(
            ...
        )
    ,  
)

Con suerte, esto proporciona lo que está buscando.

saludos
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
parry2k
Super User
Super User

@M_OVAISJANZEB puede utilizar la función switch para aplicar la misma instrucción case, algo como esto

New Column = 
SWTCIH ( TRUE(),
Table[Column] = "ABC", "Return value",
Table[Column] = "XYZ", "Return value"
)

y también puede tener un conmutador anidado.

Me gustaría elogiossi mi solución ayudara.👉Si puedes pasar tiempo publicando la pregunta, también puedes hacer esfuerzos para dar a Kudos quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!

Visítenos enhttps://perytus.com, su ventanilla única para proyectos/formación/consulta relacionadas con Power BI.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.