Forum Discussion

setis's avatar
setis
Icon for Post Partisan rankPost Partisan
7 years ago
Solved

FILTER with 2 conditions

Dear experts, 

 

I am struggling with a simple filter and I can't figure out what's wrong. 

 

If this information is not enough, I'll try to reproduce the error on a dummy file. 

 

I need a measure to get the amount of open sales (Column "Open"=1) and the column CPG="INTRA".

 

I just created a measure for the total amount for the table:

TotalSales(LCY) = SUM('CLE$Cust_ Ledger Entry'[Sales (LCY)])

and for the measure I'm trying:

 

OpenSales = 
VAR Opensales = CALCULATE([Total Sales (LCY)];'CLE$Cust_ Ledger Entry'[Open]=1)
return
CALCULATE(Opensales;
FILTER('CLE$Cust_ Ledger Entry';'CLE$Cust_ Ledger Entry'[CPG]="INTRA"))

I am obtaining wrong results. When I place the measure in a table, I am obtaining lines with the column [Open] 1 and 0 and will all types of CPG.

 

Is this enough to identify the mistake? Can somebody let me know what I'm doing wrong?

 

Thanks in advance

 

 

  • Hi setis 

    First thing that stands out is that you are using a variable as first argument in the CALCULATE. Bear in mind that variables in DAX are immutable after declaration. That is, the result of that CALCULATE will be the value that Opensales was assigned at declaration, irrespective of the filters in the CALCULATE

    Try using the measure directly (or its expanded code) instead of the VAR

    Cheers

         

2 Replies

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

    Hi setis 

    First thing that stands out is that you are using a variable as first argument in the CALCULATE. Bear in mind that variables in DAX are immutable after declaration. That is, the result of that CALCULATE will be the value that Opensales was assigned at declaration, irrespective of the filters in the CALCULATE

    Try using the measure directly (or its expanded code) instead of the VAR

    Cheers

         

    • setis's avatar
      setis
      Icon for Post Partisan rankPost Partisan

      Thanks a lot AlB removing the variables actually solved the issue