Forum Discussion

rber's avatar
rber
Frequent Visitor
6 years ago

How to divide two rows in matrix based on certain condition with DAX

Hi all! I created a visual matrix which I want to divide some rows by a specific row and show the results through a measure. My matrix is shown below. I want to divide all the rows with ID_Perc = 1 by the single row with ID_Perc = 2

I have already managed to show only results from the rows I want, but unfortunately I can't divide properly. My measure is:

 

% Realizado =
VAR varValorPercentual = 100
VAR varPercentual = SELECTEDVALUE(DRE_Ordem[ID_Percentual])
RETURN

SWITCH(

TRUE();

varPercentual = 1 && NOT(ISINSCOPE(dPlanoDeContas[Nível 1 - PdC])); Abs(varValorPercentual);

BLANK())

 

And my visual matrix...

 

 

 

Thanks a lot!

Regards,

2 Replies

  • camargos88's avatar
    camargos88
    Icon for Community Champion rankCommunity Champion

    Hi rber ,

     

    I would guess something like:

     

    VAR _total = CALCULATE(SUM('Table'[Valor]); FILTER(ALL('Table'); 'Table'[ID_PER] = 2))
    var _valor = CALCULATE(SUM('Table'[Valor]); 'Table'[ID_PER] = 1)
    return DIVIDE(_valor; _total; 0)

     

    Ricardo

     

  • v-yuta-msft's avatar
    v-yuta-msft
    Icon for Community Support rankCommunity Support

    rber ,

     

    I'm confused on your description, could you share some sample data and clarify more details about your requirement?

     

    Regards,

    Jimmy Tao