Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Wrong Grand Totals Using SWITCH

Inscrição RAP =
VAR InscricaoRAP = CALCULATE(
SUMX(
fEmpenho;
fEmpenho[Saldo - R$ (Conta Contábil)]);
FILTER(fEmpenho;fEmpenho[Conta Contábil] = "622920105"
))
VAR InscricaoRAPLiquidar = CALCULATE(
SUMX(
fEmpenho;
fEmpenho[Saldo - R$ (Conta Contábil)]);
FILTER(fEmpenho;fEmpenho[Conta Contábil] = "531110100"
))

VAR ReinscricaoRAP = CALCULATE(
SUMX(
fEmpenho;
fEmpenho[Saldo - R$ (Conta Contábil)]);
FILTER(fEmpenho;fEmpenho[Conta Contábil] = "531210000"
))

VAR InscricaoConsolidada = SWITCH(
TRUE();
InscricaoRAP <> BLANK(); InscricaoRAP;
InscricaoRAPLiquidar <> BLANK(); InscricaoRAPLiquidar;
ReinscricaoRAP
)
RETURN

InscricaoConsolidada
 
  • Hi Anonymous ,

     

    We can try to use the following measure to meet your requirement, the 'Table'[Column] means the first column you used in the table visual:

     

    Inscrição RAP =
    SUMX (
        SUMMARIZE (
            'Table';
            'Table'[Column];
            "Result";
            VAR InscricaoRAP =
                CALCULATE (
                    SUM ( fEmpenho[Saldo - R$ (Conta Contábil)] );
                    fEmpenho[Conta Contábil] = "622920105"
                )
            VAR InscricaoRAPLiquidar =
                CALCULATE (
                    SUM ( fEmpenho[Saldo - R$ (Conta Contábil)] );
                    fEmpenho[Conta Contábil] = "531110100"
                )
            VAR ReinscricaoRAP =
                CALCULATE (
                    SUM ( fEmpenho[Saldo - R$ (Conta Contábil)] );
                    fEmpenho[Conta Contábil] = "531210000"
                )
            VAR InscricaoConsolidada =
                SWITCH (
                    TRUE ();
                    InscricaoRAP <> BLANK (); InscricaoRAP;
                    InscricaoRAPLiquidar <> BLANK (); InscricaoRAPLiquidar;
                    ReinscricaoRAP
                )
            RETURN
                InscricaoConsolidada
        );
        [Result]
    )

     


    If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


    Best regards,

     

6 Replies

  • kentyler's avatar
    kentyler
    Solution Sage

    Could you tell us what you expect the totals to be ? and which lines are in error ?

    • Anonymous's avatar
      Anonymous
      Not applicable

      The lines are corrects, just the grand total are wrong.

      • kentyler's avatar
        kentyler
        Solution Sage

        Generally, that kind of problem means there is some issue with the filter context.

        if you RETURN each of the VARs do you see the results you expect

        for example

        Inscrição RAP =
        VAR InscricaoRAP = CALCULATE(
        SUMX(
        fEmpenho;
        fEmpenho[Saldo - R$ (Conta Contábil)]);
        FILTER(fEmpenho;fEmpenho[Conta Contábil] = "622920105"
        ))
        VAR InscricaoRAPLiquidar = CALCULATE(
        SUMX(
        fEmpenho;
        fEmpenho[Saldo - R$ (Conta Contábil)]);
        FILTER(fEmpenho;fEmpenho[Conta Contábil] = "531110100"
        ))

         

        VAR ReinscricaoRAP = CALCULATE(
        SUMX(
        fEmpenho;
        fEmpenho[Saldo - R$ (Conta Contábil)]);
        FILTER(fEmpenho;fEmpenho[Conta Contábil] = "531210000"
        ))

         

        VAR InscricaoConsolidada = SWITCH(
        TRUE();
        InscricaoRAP < 0; InscricaoRAP;
        InscricaoRAPLiquidar <> BLANK(); InscricaoRAPLiquidar;
        ReinscricaoRAP
        )
        RETURN

         

        ReinscricaoRAP
  • v-lid-msft's avatar
    v-lid-msft
    Community Support

    Hi Anonymous ,

     

    We can try to use the following measure to meet your requirement, the 'Table'[Column] means the first column you used in the table visual:

     

    Inscrição RAP =
    SUMX (
        SUMMARIZE (
            'Table';
            'Table'[Column];
            "Result";
            VAR InscricaoRAP =
                CALCULATE (
                    SUM ( fEmpenho[Saldo - R$ (Conta Contábil)] );
                    fEmpenho[Conta Contábil] = "622920105"
                )
            VAR InscricaoRAPLiquidar =
                CALCULATE (
                    SUM ( fEmpenho[Saldo - R$ (Conta Contábil)] );
                    fEmpenho[Conta Contábil] = "531110100"
                )
            VAR ReinscricaoRAP =
                CALCULATE (
                    SUM ( fEmpenho[Saldo - R$ (Conta Contábil)] );
                    fEmpenho[Conta Contábil] = "531210000"
                )
            VAR InscricaoConsolidada =
                SWITCH (
                    TRUE ();
                    InscricaoRAP <> BLANK (); InscricaoRAP;
                    InscricaoRAPLiquidar <> BLANK (); InscricaoRAPLiquidar;
                    ReinscricaoRAP
                )
            RETURN
                InscricaoConsolidada
        );
        [Result]
    )

     


    If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


    Best regards,