Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
2 years ago
Solved

query mysql to DAX

Hello

How do I move this MySQL query to Power BI DAX?

SELECT COUNT(total) AS Contador, Sum(cantidad) as canti FROM (SELECT COUNT(*) AS total,sat_reparacion.cantidad FROM sat_reparacion INNER JOIN sat_lineas ON sat_reparacion.codigo_reparacion=sat_lineas.documento GROUP BY sat_lineas.documento HAVING (SUM(sat_lineas.pvp)=0)) ";

Thank you.

  • Hello,

     

    Not sure of what you are trying to achieve doing this but :

     

    Contador = COUNTROWS(
        FILTER(
            SUMMARIZE(
                FILTER(
                    sat_reparacion,
                    CALCULATE(SUM(sat_lineas[pvp])) = 0
                ),
                sat_lineas[documento],
                "Contador", COUNTROWS(sat_reparacion),
                "canti", SUM(sat_reparacion[cantidad])
            ),
            [Contador] > 0
        )
    )

     

    Igna

4 Replies

  • Igna's avatar
    Igna
    Icon for Resolver III rankResolver III

    Hello,

     

    Not sure of what you are trying to achieve doing this but :

     

    Contador = COUNTROWS(
        FILTER(
            SUMMARIZE(
                FILTER(
                    sat_reparacion,
                    CALCULATE(SUM(sat_lineas[pvp])) = 0
                ),
                sat_lineas[documento],
                "Contador", COUNTROWS(sat_reparacion),
                "canti", SUM(sat_reparacion[cantidad])
            ),
            [Contador] > 0
        )
    )

     

    Igna

  • It's perfect! Thank you

    The explanation of what I wanted is:

    I've got these two boards

    Table of Controls

    control
    T1
    T2
    T3
    T4
    T5

    Table of Lines Controls

    controlpvp
    T10
    T10
    T10
    T23
    T24
    T30
    T41
    T41
    T41

    As you can see, control T1, the sum of pvp in the table lines controls is 0, control T3 also adds 0, so the expected result I would want would be 2, since controls with 0 are 2

    Anyway, with the previous measure it has worked perfectly for me.

    Best regards

    • Igna's avatar
      Igna
      Icon for Resolver III rankResolver III

      Happy to hear 🙂

       

      Can you mark this topic as solved ?

       

      Best regards,

       

      Igna

      • Syndicate_Admin's avatar
        Syndicate_Admin
        Icon for Administrator rankAdministrator

        Sorry

        I have a similar query but I'm not able to get it in DAX. The new query is:

        SELECT COUNT(total) AS Contador 
        FROM (
            SELECT COUNT(*) AS total FROM sat_reparacion INNER JOIN sat_lineas ON sat_reparacion.codigo_reparacion=sat_lineas.documento
            WHERE 
                (
                no_reparable=0 OR no_reparable IS NULL 
                ) 
            AND (
                garantia = 0 OR GARANTIA IS NULL
                )
            GROUP BY sat_lineas.documento 
            HAVING (SUM(sat_lineas.pvp)=0
            )
        )t1

        Let's see if you can give me a hand.

        Thank you.